Вопрос по javascript, ajax – Как определить время ожидания вызова AJAX (XmlHttpRequest) в браузере?

42

Error: User Rate Limit ExceededXMLHttpRequestError: User Rate Limit Exceeded

var xmlHttp = new XMLHttpRequest();  // Assumes native object

xmlHttp.open("GET", "http://www.example.com", false);

xmlHttp.send("");

var statusCode = xmlHttp.status;
// Process it, and I'd love to know if the request timed out

Error: User Rate Limit Exceededwindow.setTimeout(function() { xmlHttp.abort() }, 30000);?

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Ваш Ответ

2   ответа
49

setTimeout:

var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
    if (xhr.readyState == 4) {
        alert("ready state = 4");
    }
};

xhr.open("POST", "http://www.service.org/myService.svc/Method", true);
xhr.setRequestHeader("Content-type", "application/json; charset=utf-8");
xhr.timeout = 4000;
xhr.ontimeout = function () { alert("Timed out!!!"); }
xhr.send(json);
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
50

UPDATE:Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded

xmlHttp.open("GET", "http://www.example.com", true);

xmlHttp.onreadystatechange=function(){
   if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
      clearTimeout(xmlHttpTimeout); 
      alert(xmlHttp.responseText);
   }
}
// Now that we're ready to handle the response, we can make the request
xmlHttp.send("");
// Timeout to abort in 5 seconds
var xmlHttpTimeout=setTimeout(ajaxTimeout,5000);
function ajaxTimeout(){
   xmlHttp.abort();
   alert("Request timed out");
}

Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit ExceededXMLHttpRequestError: User Rate Limit Exceeded


xmlHttp.ontimeout = function(){
  alert("request timed out");
}

Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded

Похожие вопросы