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();
精彩评论