我正在测试jQuery ajax请求的错误回调,我有一个问题。下面是我的Ajax请求jQuery ajax请求错误回调
$.ajax({
type:'get',
url:'non-existant-file.php',
data: { newFile : $('#name').val() },
beforeSend: function() {
// make nice image to show the request is running
},
success: function() {
// show results of successfull request
},
error: function(jq,status,message) {
alert('A jQuery error has occurred. Status: ' + status + ' - Message: ' + message);
}
});
该文件不存在,测试时引发错误的唯一目的。我期望它返回一个404作为状态,并且'File not found'作为消息。 ATLEAST,这就是我所理解的是,当我读了docs:
Possible values for the second argument (besides null) are "timeout", "error", "abort", and "parsererror". When an HTTP error occurs, errorThrown receives the textual portion of the HTTP status, such as "Not Found" or "Internal Server Error." As of jQuery 1.5, the error setting can accept an array of functions. Each function will be called in turn.
但是,我得到的警告没有像我所期待的:
A jQuery error has occurred. Status: error - Message: undefined
我是理解的文档错误还是我只是不正确?
你在的情况下,应用程序中有一个错误页的URL不存在? – davids
像一个默认的404页面?那就不要。我不。在铬错误控制台它只是抛出'GET http://localhost/km/admin/createFile.php?newFile = 404(未找到)',我会想到的是,将返回ajax错误的方式。 – Albert