1、属性提示错误 error:function(){}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="js/jquery-1.10.1.min.js"></script>
<script src="docm.js"></script>
</head>
<body>
<form>
用户名:<input type="text" name="user" id="user">
邮件:<input type="text" name="email" id="email">
<input type="button" value="提交">
</form>
<div id="box"></div>
</body>
</html>
$(function(){
$('form input[type=button]').click(function(){
$.ajax({
type:'POST',
url:'user.php', //写一个错误的地址
data:$('form').serialize(),
success:function(response,status,xhr){
$('#box').html(response);
}
});
});
error:function(xhr,errorText,errorType) { //xhr:XMLHttpRequest对象 errorText:错误信息 erroType:(可选)捕获的异常对象
alert('错误'); //自定义错误
alert(errorText + ':' + errorType);
alert(xmr.status + ':' + xmr, statusText);
}
})
2、$.post()使用连缀.error()方法提示错误,连缀方法将被.fail()取代
$.post('test1.php').error(function (xhr, status, info) {
alert(xhr.status + ':' +xhr.statusText);
alert(status + ':' + info);
});
3、$.post()使用全局.ajaxError()事件提示错误
$(document).ajaxError(function (event, xhr, settings, infoError) {
alert(xhr.status + ':' +xhr.statusText);
alert(settings+ ':' + info);
alert(event.type);
alert(settings.url);
//for(var i in event){ //查找event、settings有哪些属性方法
// document.wirte(i+<br>);
// }
});