CORSをサポートしていないサーバーからjsonデータを取得しようとしています。私はJSONPはstituationのようなもののためのソリューションです読んで、私はまだそれを動作させることはできません。 私のコードを:API CORSからデータを取得
var headers = {
'Authorization': 'Bearer ' + 'token',
'Accept': 'application/json'
};
function myCallbackFunction(data){
$('body').text(data.response);
}
$.ajax({
type: "GET",
headers : headers,
url: "https://site/api/etc",
dataType: "jsonp",
success: function(data){console.log(data);},
jsonp: false,
jsonpCallback : "myCallbackFunction",
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
私はこの
error: Uncaught SyntaxError: Unexpected token :
を取得する私は、サーバーが返すので、それを知っています
XMLHttpRequest cannot load https://site/api/1.0/etc . Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' http://site ' is therefore not allowed access.
CORSを意味し、サーバ側でサポートされていない:JSONデータは、しかし、私は変更データ型はJSONする場合、私はCORS関連のエラーを取得するために正しい方法がわかりませんしかし私はそれが私が理解していない作品郵便配達を使用しています。 私は他の多くのことを試みましたが、データを取得することができました。 助けてください。 ありがとうございます。 PS:私はちょうどここに私のために働いていたものを出してあげる