开发者

Return xmlhttpRequest if no text present in the asked page

开发者 https://www.devze.com 2023-04-03 13:17 出处:网络
i want to recall the GM_xmlhttpRequest if there is not text answered in the page, like a loop. GM_xmlhttpRequest({

i want to recall the GM_xmlhttpRequest if there is not text answered in the page, like a loop.

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        
            }
        }   
    });

How can i do it? Thanks from now.


Put your request code into a function and simply call it again if the request fails. Something like this:

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消