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:
Get the image and click upload to start uploading.
Save the image every time you get it.File name + time
In the variable, when the user clicks multiple uploadsFile name + time
Compared 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)
If the image is inconsistent and the first request has not been interruptedajax abort
Initiate the second upload request