我試圖讓使用JSON 從外部API使用XMLHttpRequest
的API URL是這樣
http://60.62.62.62:8586/api/village/197571446817
而且數據是這樣的一個API的一些數據JSON API錯誤:
{
"userId": 197571446817,
"currentHomeId": 197571446817,
"clanId": 15489654523,
"clanName": "vlsn_nsmr",
"clanBadge": 1744850005,
"clanRole": "title",
"clanWar": 7,
"numberLogin": 0,
"secondsLogin": 0,
"league": "CRYSTAL_III",
"townHallLevel": 9,
"userName": "somename",
"level": 114,
"XP": 5516,
"gems": -234935969,
"freeGems": 0,
"attackRating": -721481846,
"attackKFactor": -1987233268,
"trophies": 1925,
"attackWinCount": 308,
"attackLoseCount": -1998035130,
"defenseWinCount": 3,
"defenseLoseCount": -840248882,
"nameChosenByUser": true,
"nameChanged": 0,
"villageImg": "",
"boughtGems": -1906210374
}
到目前爲止好。但後來我嘗試使用的getJSON得到一些值:
$.getJSON('http://62.4.23.229:8338/api/village/197571446817', function(data) {
console.log(data.userName)
}
而且我得到這個:
的XMLHttpRequest無法加載URL沒有「訪問控制允許來源」標頭出現在所請求的資源Origin
我試過使用jsonp,但沒有運氣似乎這個API不喜歡回調。有誰知道我如何從該API獲取該信息?
的可能的複製[XMLHttpRequest的不能加載與jQuery一個URL](http://stackoverflow.com/questions/3828982/xmlhttprequest-cannot-load-an-url-with-jquery) –