Search code examples
javascriptjqueryjsonp

Trying to get JSONP but JS thinks that I'm pointing to other JS file


I'm trying to download JSONP from other server but I still getting error (in FF inspector SyntaxError: missing ; before statement). To connect with server I'm using simple $.getJSON:

$.getJSON(url + "?callback=?", function(data) {
            $("#main").html(data);       
});

On the server I have this JSON:

{"branchName":"war140820rc1","commitId":"fcf600371bc9e837290799e0d7f7e848ccf12e7d"}

What is my problem? I checked this code multiple times and it looks like other JSONP downloaders.


Solution

  • Keep in mind that the request will look something like this:

    <script src="http://yourdomain.com/?callback=callback"></script>
    

    Which means it is handled as a Javascript file. Therefor you the callback passed in ?callback= should be called like every other javascript function, and you pass the result in json. Like:

    callback(<?= MYJSON ?>);