3 javascript jquery internet-explorer internet-explorer-8
我搜索过高低,但是甚至没有提到它.使用jQuery 1.4.4(没有其他库),到目前为止只在Internet Explorer 8上发生.错误是"对象不支持此属性或方法",它指向的行在下面,at $.post(.
HTML是无与伦比的,所以我只想发布JS.
$(window).load(function(){
$("input[type='submit']", ".scope").live("click", function(e){
e.preventDefault();
// some intervening code defining variables used below...
//only var which is at all complex
var inputs = $form.find(":input").serializeArray();
$.post(
action,
inputs,
function(data){
var $json = $.parseJSON(data);
if ( $json.success == true ) {
if ( testVar == 2 ) {
if ( $json.tabkill == true ) {
killTab(tabID);
} else {
loadPane(rID,tabID,"refreshTop");
}
} else {
loadPane(rID,tabID);
}
} else {
//modal dialogue error message, excised
}
}
).ajaxError(function(e, xhr, settings, exception) {
if (settings.url == action) {
alert("Problem calling: "+settings.url+"\n code: "+xhr.status+"\n exception: "+exception);
}
});
return false;
});
//end window load block
});
Run Code Online (Sandbox Code Playgroud)
问题在于您的生产线ajaxError.
问题是$.post返回一个XMLHTTPRequest对象,而不是一个jQuery选择.ajaxError必须在jQuery选择上调用.
有两种安全的方法:
1)升级到jQuery 1.5.这引入了一个新的XMLHTTPRequest包装器对象jqXHR.您可以按照error尝试的方式使用处理程序:
$.post(
action,
inputs,
function(data){
/* ... */
}
).error(function(){
alert ("Problem calling: " + action + "\nCode: " + this.status + "\nException: " + this.statusText);
});
Run Code Online (Sandbox Code Playgroud)
2)使用直接调用$.ajax并设置error处理程序:
$.ajax({
url: action,
data: inputs,
success: function(data){
/* ... */
},
error: function(xhr, textStatus, error) {
alert("Problem calling: " + action + "\nCode: " + xhr.status + "\nException: " + textStatus);
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2311 次 |
| 最近记录: |