2011-09-07 3 views
0

페이지에 텍스트가없는 경우 루프처럼 GM_xmlhttpRequest를 호출하고 싶습니다.요청 된 페이지에 텍스트가없는 경우 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   
      } 
     } 
    }); 

어떻게하면됩니까? 지금 감사합니다.

답변

0

요청 코드를 함수에 넣고 요청이 실패하면 다시 호출하면됩니다. 이 같은 것을 :

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

정말 고마워. 그것은 작동합니다 :) – Buterrip

+0

@ Buterrip : 답변을 수락 해 주시기 바랍니다;). http://stackoverflow.com/faq#howtoask –

관련 문제