单击"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 ×1