Вернуть xmlhttpRequest, если на запрашиваемой странице нет текста - PullRequest
0 голосов
/ 07 сентября 2011

Я хочу вспомнить GM_xmlhttpRequest, если на странице нет ответа, например, цикл.

GM_xmlhttpRequest({
            method: 'POST',
            url: 'http://localhost/getcaptcha.php',
            data: 'login='+login+'&password='+password,
            headers: {
            "Content-Type": "application/x-www-form-urlencoded"
            },
            onload: function(responseDetails) {
            if(responseDetails.responseText.length==3) {
            // do something
            }
            else{
                // i wanna go back to the GM_xmlhttpRequest again while there's no answer with the length==3        
            }
        }   
    });

Как я могу это сделать?Спасибо теперь.

1 Ответ

0 голосов
/ 07 сентября 2011

Поместите ваш код запроса в функцию и просто вызовите его снова, если запрос не удался.Как то так:

function sendRequest(attempt)
{
  // If the parameter is missing then this is our first attempt
  if (typeof attempt == "undefined")
    attempt = 1;

  GM_xmlhttpRequest({
    ...
    // If request failed and we tried less than three times - try again
    if (attempt <= 3)
      sendRequest(attempt + 1);
    ...
  });
}

sendRequest();
...