在我宣佈我的問題之前,是的,我知道有關於此問題的其他線程,但不知道那麼或不能使用它們在我的項目。沒有「訪問控制允許來源」標題存在於蒸汽庫存的請求資源
所以現在到了這個問題。當我運行我的代碼時,如何在標題中看到標題,我得到的答案不是「Access-Control-Allow-Origin」標題。所以也許任何人都可以幫我找到這個錯誤。
代碼:
function GetInv(){
var json_obj = JSON.parse(Get('http://steamcommunity.com/inventory/76561198122209518/730/2?l=english&count=5000'));
var assets = json_obj.assets;
console.log(json_obj);
}
function Get(yourUrl){
var Httpreq = new XMLHttpRequest(); // a new request
Httpreq.open("GET",yourUrl,false);
Httpreq.send(null);
return Httpreq.responseText;
}
編輯
謝謝你的答案所以我用Google搜索非CORS兼容的工具,我發現這一點:http://www.test-cors.org/它給了我這個代碼片段:
var createCORSRequest = function(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// Most browsers.
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
// IE8 & IE9
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
// CORS not supported.
xhr = null;
}
return xhr;
};
var url = 'http://api.steampowered.com/ISteamEconomy/GetAssetClassInfo/v0001/?key=XXXXXXXXXXXXX&appid=730&class_count=1&classid0=1131459905';
var method = 'GET';
var xhr = createCORSRequest(method, url);
xhr.onload = function() {
console.log("super");
};
xhr.onerror = function() {
console.log("failed");
};
xhr.send();
我試過了,但仍然是同樣的錯。所以,我要正確的方式,還是我愚蠢的找到答案?
可能有[jQuery xml錯誤'No'Access-Control-Allow-Origin'標頭存在請求的資源。'](http://stackoverflow.com/questions/19821753/jquery-xml-error-no-access-control-allow-origin-header-is-present-on-the-req) – MayorMonty