How to create a JSONP request, and how to handle a JSONP response.
Has anyone come across this?
And in general, is there a difference between JSON and JSONP?
thank
How to create a JSONP request, and how to handle a JSONP response.
Has anyone come across this?
And in general, is there a difference between JSON and JSONP?
thank
The difference is definitely there. JSON is a simple data format, and JSONP is a methodology for using this format with cross-domain AJAX requests.
Common JSON :
{"why":"not"} JSONP :
bestFunction({"why":"not"}); It turns out that you can use JSONP as a script. The bestFunction function that you wrote earlier will be called, and when it is launched, it will be passed JSON as a parameter. This method is used to provide cross-domain AJAX requests.
Processing might look like this:
function bestFunction(json){ console.log(json.why); } var elm = document.createElement("script"); elm.setAttribute("type", "text/javascript"); elm.src = "http://test.ru/jsonp"; document.body.appendChild(elm); Essentially, you add a script tag to your page, which loads the data in the form of a JavaScript script and makes a callback to your code with the data. Therefore, you can request data from any server, in any browser, without any permissions and additional checks that are present in AJAX requests.
Source: https://ru.stackoverflow.com/questions/550312/
All Articles