과거에 웹킷 기반 브라우저로 작업 할 때이 문제에 직면했습니다. 웹 서버에서 요청 추적을 사용하지 못하게 한 후 요청이 브라우저에서 전송되지 않은 것으로 나타났습니다. 웹 브라우저에서 자세한 디버깅을 사용하면 브라우저 자체의 버그가 지적됩니다. 브라우저에서 뛰어난 버그가 발생하여 마침내 다음 솔루션에 도달했습니다.
이 코드는 브라우저에서 반환 된 상태 코드가 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;
}
}
는 Ajax 요청을하는 데 사용하는 관련 코드, 당신은 호출하고있는 서버 코드를 게시하시기 바랍니다. 문제 진단을 시작하는 가장 좋은 방법이라고 할 수 있습니다. –