看起来Jquery.Form插件中没有错误处理功能,这非常令人沮丧。即使文档说我们可以使用$.ajax选项,但当服务器返回错误时,特别是500和400系列时,我仍然无法使用'error'选项。这个插件是否完全不能处理来自服务器的任何错误,还是一个错误等?请问有人能告诉我如何使用这个插件处理错误(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;
});