$.ajax({
url: "http://192.168.153.131:8080/api/stats",
type: "GET",
dataType: 'JSONP',
jsonpCallback: 'jsonCallback'
});
function jsonCallback(response) {
console.log(JSON.parse(response));
}
我有一个服务器正在为此URL提供JSON,并且无法启用CORS,因此我需要一种方法来解决这个问题。我试图使用JSONP,但我似乎无法让它工作。
这是我在Google Chrome控制台中获得的回复:
{"time":1516239458,"global":{"workers":0,"hashrate":0},"algos":{"scrypt-n":{"workers":0,"hashrate":0,"hashrateString":"0.00 KH"}},"pools":{"garlicoin":{"name":"garlicoin","symbol":"GRLC","algorithm":"scrypt-n","poolStats":{"validShares":"198","validBlocks":"1","invalidShares":"7","totalPaid":0},"blocks":{"pending":1,"confirmed":0,"orphaned":0},"workers":{},"hashrate":0,"workerCount":0,"hashrateString":"0.00 KH"}}}
哪个似乎有效,但仍然会出错。
答案 0 :(得分:0)
您不需要解析响应,因为已经将其解析为JSONObject
$.ajax({
url: "http://192.168.153.131:8080/api/stats",
type: "GET",
dataType: 'JSONP',
jsonpCallback: 'jsonCallback'
});
function jsonCallback(response) {
console.log(response);
}