Web アプリケーション フォルダーにはなく、GET 要求によってレベルアップしている XML ドキュメントを読み込もうとしています。loadXMLDoc は FF と chrome では正常に機能しますが、XDR は IE では機能しません。
私はこのようにメソッドを呼び出しています:
xmlDoc = loadXMLDoc("../XML/stops_group1.xml");
問題はルート ディレクトリの 1 レベル上にあることにあると思われます。これは、同じディレクトリ フォルダに対して正常に機能するためです。
function loadXMLDoc(url) {
if (typeof XDomainRequest != 'undefined') {
var xdr = new XDomainRequest();
xdr.contentType = "text/plain";
xdr.timeout = 5000;
if (xdr) {
xdr.onerror = function () {
alert('XDR onerror');
alert("Got: " + xdr.responseText);
};
xdr.ontimeout = function () {
alert('XDR ontimeout');
alert("Got: " + xdr.responseText);
};
xdr.onprogress = function () {
alert("XDR onprogress");
alert("Got: " + xdr.responseText);
};
xdr.onload = function () {
alert('onload' + xdr.responseText);
callback(xdr.responseText);
};
// 2. Open connection with server using GET method
xdr.open("get", url);
// 3. Send string data to server
xdr.send("");
} else {
alert('failed to create xdr');
}
return xdr.responseXML;
}
var xhr = createCORSRequest('GET', url);
if (!xhr) {
throw new Error('CORS not supported');
}
xhr.send("");
return xhr.responseXML;
}
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// Check if the XMLHttpRequest object has a "withCredentials" property.
// "withCredentials" only exists on XMLHTTPRequest2 objects.
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
// Otherwise, check if XDomainRequest.
// XDomainRequest only exists in IE, and is IE's way of making CORS requests.
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
// Otherwise, CORS is not supported by the browser.
xhr = null;
}
return xhr;
}
私はすでに web.config ファイルに Access-Control-Allow-Origin を追加しようとしました
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
しかし、まだ responseText が空で onError の警告メッセージが表示されます...
手がかりはありますか?