Javascript-how do I delete images uploaded through ajax multiple times ??

Source: Internet
Author: User
Currently, my program is to modify the front-end ajax avatar and then upload the modified image to the backend. It is found that when you click the upload button multiple times, the image will be uploaded multiple times. It is inconvenient to delete. Do you have any suggestions? Currently, my program is to modify the front-end ajax avatar and then upload the modified image to the backend.
It is found that when you click the upload button multiple times, the image will be uploaded multiple times. It is inconvenient to delete.
Do you have any suggestions?

Reply content:

Currently, my program is to modify the front-end ajax avatar and then upload the modified image to the backend.
It is found that when you click the upload button multiple times, the image will be uploaded multiple times. It is inconvenient to delete.
Do you have any suggestions?

During upload, the upload button is blocked.

BeforeSend: function () {// disable button to prevent repeated submission $ ("# submit"). attr ({disabled: "disabled "});}

Use benforeSend...

$. Ajax ({type: "", data: "", dataType: "", url: "", beforeSend: function () {// disable the button to prevent repeated submission $ ("# submit "). attr ({disabled: "disabled"}) ;}, success: function (data) {}, complete: function () {$ ("# submit "). removeAttr ("disabled") ;}, error: function (data ){}});

After a user uploads an avatar, the avatar can be named "user _ user ID". each time the avatar is uploaded to the server, the original image is deleted based on the name.

Optimization suggestions for such details:

  1. Get the image and click upload to start uploading.

  2. Save the image every time you get it.File name + timeIn the variable, when the user clicks multiple uploadsFile name + timeCompared with the variables, if they are the same, the request will not be processed again (the user's file name + time are too few, and further fault tolerance processing can be omitted here)

  3. If the image is inconsistent and the first request has not been interruptedajax abortInitiate the second upload request

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.