【问题标题】:How to use JSONP?如何使用 JSONP?
【发布时间】:2016-08-30 02:26:38
【问题描述】:

我正在使用的示例can be found on this link

我的 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/jsonp?symbol=AAPL&callback=myRun', function(data){
    console.log(selfish.data.Symbol);
});  

【问题讨论】:

  • 阅读 docs for getJSON 具体如何使其成为 JSONP - 提示,您需要像 somecallback=? 这样的东西作为 URL 中的搜索字符串 ... ? 实际上是 @987654327 @ 和 somecallback 取决于你调用的 API

标签: javascript jquery json jsonp


【解决方案1】:
 $.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:");
    }
});

【讨论】:

    猜你喜欢
    • 2012-12-27
    • 2011-12-10
    • 2019-05-29
    • 2012-12-24
    • 2014-06-12
    • 2015-06-20
    • 2015-09-20
    • 2013-12-14
    • 2012-05-17
    相关资源
    最近更新 更多