Jquery.Form 插件中似乎没有错误处理工具,这很令人沮丧。即使文档说我们可以使用 $.ajax 选项,当服务器返回错误时,我仍然无法使用 'error' 选项,尤其是 500 和 400 系列。是这个插件根本无法处理来自服务器的任何错误,还是一个错误等?有人可以告诉我如何使用此插件处理错误(400、500 等)吗?我需要你的帮助......我想要的只是一个简单的错误处理......谢谢。
$("#uploadingImg").hide();
var options = {//Define ajax options
type: "post",
target: "#responsePanel",
beforeSend: function(){
$("#uploadingImg").show();
},
complete: function(xhr, textStatus){
$("#uploadingImg").hide();
},
success: function(response, statusString, xhr, $form){
// I know what to do here since this option works fine
},
error: function(response, status, err){
// This option doesn't catch any of the error below,
// everything is always 'OK' a.k.a 200
if(response.status == 400){
console.log("Sorry, this is bad request!");
}
if(response.status == 601){
sessionTimedOut();
}
}
}
$("#polygonUploadForm").submit(function(){
$(this).ajaxSubmit(options); // Using the jquery.form plugin
return false;
});