使用jquery.form.js插件,提交表单的时间,提示错误$.handleError is not a function
的错误,完整错误如下:
TypeError: $.handleError is not a function jquery.form.js:339:7
错误原因:
$.handleError
存在于jQuery-1.4.2之前的版本中,jQuery-1.4.2之后的版本废弃了$.handleError
解决方法:
1、把jquery.js库换成1.4.2之前的版本。(不推荐该方法)
2、在使用的jquery.js文件中添加以下代码:(推荐)
jQuery.extend({
handleError: function (s, xhr, status, e) {
if (s.error) {
s.error.call(s.context || s, xhr, status, e);
}
if (s.global) {
(s.context ? jQuery(s.context) : jQuery.event).trigger("ajaxError", [xhr, s, e]);
}
},
httpData: function (xhr, type, s) {
var ct = xhr.getResponseHeader("content-type"),
xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0,
data = xml ?
xhr.responseXML : xhr.responseText;
if (xml && data.documentElement.tagName == "parsererror")
throw "parsererror";
if (s && s.dataFilter)
data = s.dataFilter(data, type);
if (typeof data === "string") {
if (type == "script")
jQuery.globalEval(data);
if (type == "json")
data = window["eval"]("(" + data + ")");
}
return data;
}
});
以上代码也可以放在jquery.form.js文件中。