'Show alert when ajax file is not uploaded
There is no problem with uploading files in the ajax code below. However, I have a question regarding the code below. For example, is there a way to report an error with ajax when the upload is rejected by the server?
For example, I am getting the following error report in my browser's developer console.
"An error occurred trying to load the resource."
Is there a way to show this error in alert()? Or can we show an alert() message when we encounter such an error?
$(document).on("change", "#files", function(e) {
e.preventDefault();
var values = $("#values").val();
var id = $("#files").attr("data-id");
var data = { upload: id };
$("#uploadform").ajaxForm({
type: "POST",
data: data,
delegation: true,
cache: false,
async: false,
beforeSubmit: function() {
alert('Uploading');
},
success: function(response) {
alert('Success!');
},error: function(){
alert('Can not uploaded');
}
}).submit();
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
