Javascript 如何在失败时召回ajax?
这是我的ajax调用Javascript 如何在失败时召回ajax?,javascript,jquery,jsp,Javascript,Jquery,Jsp,这是我的ajax调用 $.ajax({ url: "getProduct", type: "POST", dataType: "xml", data: { productid: $("#serviceequip1").val() }, error: function(){ }, success: function(xml){
$.ajax({
url: "getProduct",
type: "POST",
dataType: "xml",
data: {
productid: $("#serviceequip1").val()
},
error: function(){
},
success: function(xml){
$(xml).find("product").each(function()
{
//do something..
});
}
});
我已经检查过浏览器的开发模式,有时它会显示ajax调用的505错误
请提出一些解决方案。只需在方法中编写此ajax调用,在ajax的失败块中,只需再次调用该方法
function ajaxCall(){
$.ajax({
url: "getProduct",
type: "POST",
dataType: "xml",
data: {
productid: $("#serviceequip1").val()
},
error: function(){
ajaxCall();
},
success: function(xml){
$(xml).find("product").each(function()
{
//do something..
});
}
});
}
定义一个函数来进行ajax调用。出现错误时,再次调用该函数
function getProduct(){
$.ajax({
url: "getProduct",
type: "POST",
dataType: "xml",
data: {
productid: $("#serviceequip1").val()
},
error: function(){
setTimeout(getProduct, 200);
},
success: function(xml){
$(xml).find("product").each(function()
{
//do something..
});
}
});
};