浏览器查看ajax的请求时间,浏览器在ajax请求后等待多久?

如果您使用的是jQuery $ .ajax调用,则可以设置timeout属性来控制请求返回并超时之前的时间长度。超时设置以毫秒为单位,因此只需将其设置为非常高的值即可。你也可以将它设置为0来表示“无限”,但在我看来,你应该设置一个高值。

注意:无限制是actually the default但大多数浏览器都有默认的超时时间。

由于超时而返回ajax调用时,它将返回一个错误状态“超时”,如果需要,您可以使用单独的情况处理该错误状态。

所以,如果你想设置为3秒的超时,在这里处理超时是一个例子:

$.ajax({

url: "/your_ajax_method/",

type: "GET",

dataType: "json",

timeout: 3000, //Set your timeout value in milliseconds or 0 for unlimited

success: function(response) { alert(response); },

error: function(jqXHR, textStatus, errorThrown) {

if(textStatus==="timeout") {

alert("Call has timed out"); //Handle the timeout

} else {

alert("Another error was returned"); //Handle other error type

}

}

});​