2017-05-04 6 views
0

사용자 세부 정보를 가져 오기 게시물 아약스 요청을 수행합니다. 요청을 할 때 응답 상태가 0 (리소스를로드하는 동안 오류가 발생했습니다.)하지만 대부분의 나는 같은 게시물에 대해 유효한 응답을 얻었습니다. 나는 내 문제와 관련된 게시물을 거의 읽지 않았으며 "크로스 도메인 상태가 0으로 반환 될 때"라고 말하면서 모두 내 사례가 아닙니다. 같은 도메인에서 요청을하고 있습니다.무작위로 사파리 브라우저에서 0으로 아약스 상태 가져 오기

0.Has 사람이 문제의이 종류를 직면 나는이 상태를 얻을 때마다 아약스 전송 이벤트가 시작되지

는? 그것은 사파리 브라우저와 관련되어 있습니까? 사전에 크롬 및 firefox.Thanks에서 잘 작동하는 것 같다

+1

는 Ajax 요청을하는 데 사용하는 관련 코드, 당신은 호출하고있는 서버 코드를 게시하시기 바랍니다. 문제 진단을 시작하는 가장 좋은 방법이라고 할 수 있습니다. –

답변

0

과거에 웹킷 기반 브라우저로 작업 할 때이 문제에 직면했습니다. 웹 서버에서 요청 추적을 사용하지 못하게 한 후 요청이 브라우저에서 전송되지 않은 것으로 나타났습니다. 웹 브라우저에서 자세한 디버깅을 사용하면 브라우저 자체의 버그가 지적됩니다. 브라우저에서 뛰어난 버그가 발생하여 마침내 다음 솔루션에 도달했습니다.

이 코드는 브라우저에서 반환 된 상태 코드가 0 인 경우 ajax 요청을 다시 시도합니다. 다른 모든 측면에서는 jQuery의 ajax 함수처럼 작동합니다. 코드에서 요청을 다시 시도 할 횟수를 구성 할 수 있습니다.

function AjaxRetry(settings, maxTries, interval) { 
    var self = this; 
    this.settings = settings; 
    this.maxTries = typeof maxTries === "number" ? maxTries : 0; 
    this.completedTries = 0; 
    this.interval = typeof interval === "number" ? interval : 0; 

    return tryAjax().promise(); 

    function tryAjax(deferred) { 
    var d = deferred || $.Deferred(); 
    $.ajax(self.settings) 
     .done(function (data, textStatus, xhr) { 
      self.completedTries += 1; 
      d.resolve(data, status, xhr); 
      self.done = true; 
     }) 
     .fail(function (xhr, textStatus, error) { 

      self.completedTries += 1; 
      var attemptRetry = false; 

      // Added in an attempt to handle the ajax errors that appear to be a flaw in the Intermec HTML5 Browser. 
      // Example error in browser debug log: Curl ERROR: Failed sending data to the peer for url 
      // This appears to be CURLE_SEND_ERROR (55) - Failed sending network data. https://curl.haxx.se/libcurl/c/libcurl-errors.html 

      // This code will retry any ajax requests that fail due to the HTML5 browser CURL error 
      if (typeof (xhr) !== 'undefined' && typeof (textStatus) !== 'undefined' && typeof (error) !== 'undefined') { 
       if (xhr.readyState === 0 && xhr.responseJSON === undefined && xhr.status === 0 && xhr.statusText === 'error') { 
        attemptRetry = true; 
       } 
      } 

      if (self.completedTries < self.maxTries && attemptRetry === true) { 
       //console.log("Waiting " + interval + "ms before retrying..."); 
       setTimeout(function() { 
        tryAjax(d); 
       }, self.interval); 
      } else { 
       d.reject(xhr, textStatus, error); 
      } 

     }); 
    return d; 
} 

}