Google で見つけたすべてを機能させるために試しましたが、成功しませんでした。
別のドメインのサーバーに HTTP 要求を呼び出そうとしています。
IE10でも、すべてのブラウザで動作します。ただし、IE9以下では正しく動作しないようです。
IE9 以前では、すべてのメソッドでボディなしでヘッダーのみを送信します。
私はjQueryを使用してAJAX呼び出しを行っています。呼び出しは別のドメインから呼び出すことができます(実際には任意のドメインから呼び出すことができます)。
JavaScript の例:
$.ajax({
url: "http://api.domain.com/path",
type: "POST",
crossDomain: true,
cache: false,
data: JSON.stringify({data:"some body data in a json format"}),
dataType: "json",
contentType: "application/json",
success: function(data, textStatus, jqXHR){
console.log("Response data: ", data, textStatus, jqXHR);
},
error: function(jqXHR, textStatus, errorThrown){
console.error("AJAX error: ", jqXHR, textStatus, errorThrown);
}
});
IE9 でのリクエスト:
POST /path HTTP/1.1
Origin: http://[some domain]
Accept-Language: en-GB
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Host: api.domain.com
Content-Length: 0
DNT: 1
Connection: Keep-Alive
Cache-Control: no-cache
Accept: */*
[no request body]
サーバーからの応答は次のとおりです。
HTTP/1.1 500 Internal Server Error
Server: MochiWeb/1.1 WebMachine/1.9.2 (someone had painted it blue)
Date: Mon, 17 Jun 2013 11:24:26 GMT
Content-Type: text/html
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
jQuery.XDomainRequestプラグインを使用していますが、役に立ちません。
私も設定されjQuery.support.cors = true;
ていますが、どちらも役に立ちません。
IE10 では、POST リクエストの前に OPTIONS リクエストを送信しますが、IE9 では POST リクエストのみを送信することに注意してください。
助言がありますか?