Javascript 如何使用JSONP?
我正在使用的示例 我的JSONP内容如下所示:Javascript 如何使用JSONP?,javascript,jquery,json,jsonp,Javascript,Jquery,Json,Jsonp,我正在使用的示例 我的JSONP内容如下所示: myRun ( { "Status": "SUCCESS", "Name": "Apple Inc", "Symbol": "AAPL", "LastPrice": 106.82, "Open": 106.62 } ) 我在下面使用的代码不起作用。我不知道如何重新组织它以使用JSONP var selfish = this; $.getJSON('http://dev.markitondemand.com/MODApis/Api/v2/Quote
myRun (
{
"Status": "SUCCESS",
"Name": "Apple Inc",
"Symbol": "AAPL",
"LastPrice": 106.82,
"Open": 106.62
}
)
我在下面使用的代码不起作用。我不知道如何重新组织它以使用JSONP
var selfish = this;
$.getJSON('http://dev.markitondemand.com/MODApis/Api/v2/Quote/jsonp?symbol=AAPL&callback=myRun', function(data){
console.log(selfish.data.Symbol);
});
请阅读getJSON,特别是如何使其成为JSONP-hint,您需要类似于somecallback=?
的内容作为URL中的搜索字符串。。。?
实际上是一个?
和somecallback
取决于您调用的API
$.ajax({
url: "url",
dataType: 'JSONP',
jsonpCallback: 'callback',
type: 'GET',
success: function (data) {
if (data.error) {
console.log ("data error:", data.error.errorMessage);
}
},
error: function (data) {
console.log ("ajax connection error:");
}
});