您可以尝试如下操作:
var attempts; function doAjaxRequest() { attempts = 0; doAjaxRequestLoop(); } function doAjaxRequestLoop() { attempts += 1; if (attempts > 10) { alert('too many attempts.'); return; } $.ajax({ // do your request error: function (error) { doAjaxRequestLoop(); } }); }</script>尽管我可能建议反对。如果请求失败,则可能要找出失败的原因。如果用户失去了互联网连接怎么办?任何进一步的尝试都可能再次失败,为什么要重试?



