jsonp callback problem

我只是一个虾纸丫 提交于 2019-12-04 18:09:03
$.ajax({
    type: "GET",
    url: "http://jsonip.appspot.com/?callback=?",
    //                                        ^
    // ---- note the ? symbol ----------------|
    // jQuery is responsible for replacing this symbol
    // with the name of the auto generated callback fn
    dataType: "jsonp",
    success: function(json) {
        var ip = json.ip;
        alert(ip);
    }
});

jsFiddle demo here.

Did you see the url that is passed across the wire? I suggest you try { jsonp: false, jsonpCallback: "callbackName" }. This will avoid jquery from adding the callback function automatically.

Also did you set cross domain to true.?

You dont need to add any callback parameter in url.

If you try http://terrasus.com/detail.jsp?articleID=396 article step by step it will work fine. if you produce jsonp response you should get the callback value and set it to your response dynamically. This article has a detail explanation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!