小编Max*_*ime的帖子

如何重复ajax调用直到成功

单击"getproduct"按钮时,如果产品不可用,则ajax调用将获取产品或404代码.

我希望每5秒再次调用函数getMyJson,直到返回产品.

有任何想法吗 ?

$(function () {
    $("#getproduct").click(function getMyJson() {
        $.ajax({
            type: "GET",
            url: "Product/GetProduct",
            dataType: "json",
            success: function (data) {
                //alert("succes");
                $("#name").html(data.Name);
                $("#price").html(data.Price);
            },
            error: function () {
                //alert("fail");
                //callback getMyJson here in 5 seconds
            }
        });
    });
});
Run Code Online (Sandbox Code Playgroud)

jquery

7
推荐指数
1
解决办法
7710
查看次数

标签 统计

jquery ×1