jQuery を使用して CORS リクエストを作成しました。これは次のように簡単です。
var BJS = {Services: {} };
BJS.Services.GetDatasources = function (data, success, fail) {
if (data == null) data = {};
var u = data["user"],
p = data["pass"],
url = data["url"],
ext = data["ext"],
secure = data["secure"] ? "https://" : "http://",
up = BJS.Base64.encode(u + ":" + p),
d = data["data"] ? data["data"] : "";
$.ajax({
url: secure + url + ext,
data: d,
headers: {
Authorization: "Basic " + up
},
success: success,
error: fail
});
};
このリクエストは Chrome で完全に機能します。IE では、エラーが返されます。
Error: Access is denied.
at send (...)
at ajax (...)
at GetDatasources (...)
at eval code (eval code:1:1)
at Global code (Unknown script code:5:1)
これは、私が信じている $.ajax リクエストを指しています。
この ajax リクエストを処理する別の方法はありますか? 異なる変数が必要ですか?
jQuery の $.ajax 呼び出しがブラウザの依存関係から抽象化され、ブラウザ間でより統一された機能が可能になることを期待していましたが、残念ながら、ここではそうではありません。
編集: セキュリティのために、タグを削除しましたが、実際にはすべての変数 DID にデフォルト値があります: 例:
u = data["user"] || "admin";
しかし、ハッシュ、URLなどを外の世界から削除したかったのです。
編集 誰も回答を投稿していませんが、好奇心旺盛な人のために行った回避策を示したいと思いますが、根本的な質問にはまだ回答がありません。
$.support.cors = true
if ($.browser.msie && parseInt($.browser.version, 10) >= 8 && XDomainRequest) {
//IE
//using a webservice will remove the cors, and you can just forward the response to the client.
//it takes up some processing time, but this is the workaround i accomplish.
$.ajax({url: "webservice.svc"}); //this can be a .php file, or anything really that runs ont he server.
}else{
//chrome/ff
//call page as normal.
$.ajax({url:"resource_file"});
}