. 밝혀지면, angle은 window.XMLHttpRequest()의 가용성을 감지하는 가장 좋은 일을하지 않습니다. jQuery는 좀 더 철저히 접근합니다.
:
AngularJS와 1.2.9
function createXhr(method) {
// IE8 doesn't support PATCH method, but the ActiveX object does
/* global ActiveXObject */
return (msie <= 8 && lowercase(method) === 'patch')
? new ActiveXObject('Microsoft.XMLHTTP')
: new window.XMLHttpRequest();
}
jQuery를 나를 위해 1.10.2
// Functions to create xhrs
function createStandardXHR() {
try {
return new window.XMLHttpRequest();
} catch(e) {}
}
function createActiveXHR() {
try {
return new window.ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {}
}
// Create the request object
// (This is still attached to ajaxSettings for backward compatibility)
jQuery.ajaxSettings.xhr = window.ActiveXObject ?
/* Microsoft failed to properly
* implement the XMLHttpRequest in IE7 (can't request local files),
* so we use the ActiveXObject when it is available
* Additionally XMLHttpRequest can be disabled in IE7/IE8 so
* we need a fallback.
*/
function() {
return !this.isLocal && createStandardXHR() || createActiveXHR();
} :
// For all other browsers, use the standard XMLHttpRequest object
createStandardXHR;
// Determine support properties
xhrSupported = jQuery.ajaxSettings.xhr();
는 수정 각도의 createXhr 방법에 IE8 문서 모드로 확인하는 추가 조건을 추가했다
function createXhr(method) {
// IE8 doesn't support PATCH method, but the ActiveX object does
/* global ActiveXObject */
return ((msie <= 8 && lowercase(method) === 'patch') ||
(msie >= 8 && document.documentMode == 8))
? new ActiveXObject('Microsoft.XMLHTTP')
: new window.XMLHttpRequest();
}
대안이 있는지 확인하기 위해 보이는 jQuery의 방식을 구현하는 것입니다 ActiveXObject 사용할 수 있습니다. 그런 다음 표준 XMLHttpRequest를 만들려고 시도하는 경우 실패하면 다시 ActiveX 대안으로 넘어갑니다.