1
我想用JavaScript和jQuery訪問API,但我得到一個奇怪的錯誤。在jQuery中的跨域請求只適用於某些文件
$(document).ready(function() {
var server = 'https://' + rand(10) + '.spotilocal.com:4371';
$.getJSON(
server + "/service/version.json?service=remote&_=" + new Date().getTime(),
function(data) {
if (data.version == 9) {
$.getJSON(
server + "/simplecsrf/token.json?&cors=&_=" + new Date().getTime(),
function(data) {
console.log(data.toString());
});
}
});
function rand(length,current){
// returns a random string
}
});
我的錯誤:
XHR finished loading: "https://rwhpxmubmi.spotilocal.com:4371/service/version.json?service=remote&_=1337093238805".
XMLHttpRequest cannot load https://rwhpxmubmi.spotilocal.com:4371/simplecsrf/token.json?&cors=&_=1337093239623. Origin http://example.com is not allowed by Access-Control-Allow-Origin.
的第一個請求成功,但第二次失敗。但是這兩個文件都在同一臺服務器上,並且這兩個文件都是JSON。
有誰知道爲什麼我會得到這個錯誤以及如何解決它?
是的,這是問題,謝謝! – Qurben