Basic example of using .ajax() with JSONP?

前端 未结 4 1917
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-21 23:54

Please could someone help me work out how to get started with JSONP?

Code:

$(\'document\').ready(function() {
    var pm_url = \'http://twitter.com/s         


        
4条回答
  •  盖世英雄少女心
    2020-11-22 00:18

    There is even easier way how to work with JSONP using jQuery

    $.getJSON("http://example.com/something.json?callback=?", function(result){
       //response data are now in the result variable
       alert(result);
    });
    

    The ? on the end of the URL tells jQuery that it is a JSONP request instead of JSON. jQuery registers and calls the callback function automatically.

    For more detail refer to the jQuery.getJSON documentation.

提交回复
热议问题