callback function doesn't work when using getJSON function in jQuery

后端 未结 8 1968
心在旅途
心在旅途 2021-01-01 15:59

I am trying to use the getJSON function in jQuery to import some data and trigger a callback function. The callback function doesn\'t run. However, if I try the same thing w

8条回答
  •  醉话见心
    2021-01-01 16:47

    $.getJSON() is JSONP, so change it this way:

    $("#test2").click(function() {
        $.getJSON("index.html?callback=?",
            function(response) {
                    alert('hi');
            }
        )
    });
    

    Server receives param callback filled with something like: jsonp1291077863309. In a response write back callback function jsonp1291077863309( PUT_JSON_HERE).

提交回复
热议问题