super.prozandr1
super.prozandr1

Reputation: 127

How get jsonp from remote server?

Please help get jsonp-data from remote server:

document.addEventListener("DOMContentLoaded", function() {
    function readresponse(response){
        console.log(response);
    }
    (function(){
        var src = 'http://json-schema.org/draft-04/schema#?callback=readresponse';
        var script = document.createElement('SCRIPT');
        script.src = src;
        document.body.appendChild(script);
    })();   
});

But chrome browser tab 'network' display 200 status and correct json response

Upvotes: 0

Views: 70

Answers (1)

Andrei Roba
Andrei Roba

Reputation: 2322

If you take a look at the content your src url is returning you will see that it's a JSON and not JSONP. If it were to be JSONP your src should be:

var src = 'http://json-schema.org/draft-04/schema&callback=readresponse'

and the data it would return would be wrapped as:

readresponse({...})

instead of just

{...}

which is why you receive the parse error.


You can find out more on this topic reading this post.

Upvotes: 1

Related Questions