我有两个函数,它们都在我的php文件上执行单独的GET调用。我正在尝试做一个$。 GET调用执行不同的任务
每当我试图得到404错误时,我就会更改此变量。
var url = "output-tv.php";
这是我的函数,如果它有404错误则会发出警告
$.ajax({
url: url,
statusCode:{
404: function(){
alert('Page not found');
}
},
success: function(data){
alert('success');
}
});
这是我创建表的函数
$.get(url,
{tv_type:tv_type,screen_size:screen_size,connectivity:connectivity,features:features},
function(response)
{
var i = 0;
var table = document.getElementById("table")
var row = table.insertRow(0);
$( ".result" ).html( statusCode );
alert( "Load was performed." );
$("#table td").remove();
$(response.result).each(function () {
var rowString = "<tr>";
rowString += "<td>" + this.product_code + "</td>
rowString += "<td>" + this.tv_name + "</td>";
rowString += "<td>" + this.size + "</td>";
rowString += "<td>" + this.tv_type + "</td>";
rowString += "</tr>";
$('#table').append(rowString);
});
我尝试过这样做,但我无法捕捉404错误。
$.get(url,
{tv_type:tv_type,screen_size:screen_size,connectivity:connectivity,features:features},
function(response, statusCode){
$(.result){
statusCode:{
404: function(){
alert('Page not found');
}
},
success: function(data){
alert('success');
}
$("#table td").remove();
$(response.result).each(function () {
var rowString = "<tr>";
rowString += "<td>" + this.product_code + "</td>";
rowString += "<td>" + this.tv_name + "</td>";
rowString += "<td>" + this.size + "</td>";
rowString += "<td>" + this.tv_type + "</td>";
rowString += "</tr>";
$('#table').append(rowString);
});
}, "json" );
答案 0 :(得分:0)
成功与失败,你必须使用完整版:
complete: function(xhr, data) {
if (xhr.status == 404)
// do something
else
//do something else
}