0

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

super.prozandr1
  • 107
  • 3
  • 10

1 Answers1

1

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.

Andrei Roba
  • 2,156
  • 2
  • 16
  • 33