似乎Jquery.Form插件中没有错误处理工具,这是非常令人沮丧的。尽管文档说我们可以使用$ .ajax选项,但当服务器返回错误时,我仍然无法使用'错误'选项,特别是500和400系列。这个插件是否无法从服务器处理任何错误,或者它是一个错误等? 有人可以告诉我如何处理这个插件的错误(400,500等)吗?我需要你的帮助...我想要的只是一个简单的错误处理...谢谢。jquery表单插件,没有错误处理
$("#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;
});
+1 * *这应该是公认的答案。 – 2011-09-27 01:38:07
+1。请注意,只有在使用iFrame解决方法时,这是一个问题 - 也就是说,在不支持HTML5功能的浏览器中。 (*咳嗽* ie *咳嗽*) – 2012-07-12 05:09:41
+1当人们花时间分享知识时,我非常喜欢。非常感谢@JCotton,我非常感谢你的明确和翔实的答案:) – will824 2013-12-05 19:19:58