Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在失败时召回ajax?_Javascript_Jquery_Jsp - Fatal编程技术网

Javascript 如何在失败时召回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调用

 $.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.. 
            });
        }
    });
  };