Is JSONP classfied as AJAX?
I am confused as i understood that the XHR is required to be used for the asynchronous communication but when i look at the jQuery code for JSONP it is "wrapped in an AJAX call
jQuery AJAX
if JSONP is not classified as AJAX then why have jQuery bundled it as an AJAX function or am i missing something here?
JSONP stands for JSON with Padding. Requesting a file from another domain can cause problems, due to cross-domain policy. Requesting an external script from another domain does not have this problem. JSONP uses this advantage, and request files using the script tag instead of the XMLHttpRequest object.
JSONP has nothing to do with Ajax, since it does not use XMLHttpRequest.
“JavaScript with Padding” (JSONP) Also called “JSON with Padding”, it is a technique for fooling a web browser into performing cross-origin requests using a special <script> tag that uses the src attribute to make a special API request.
JSONP is vulnerable to the data source replacing the innocuous function call with malicious code, which is why it has been superseded by cross-origin resource sharing (available since 2009) in modern applications.
If you'd strictly say that AJAX means "asynchronous communication between JavaScript and a Server using XML format", then only a few techniques called "Ajax" today would meet that definition, as even many "XML-HTTP-Requests" do not transport XML data.
So the JSONP technique is just one of the known asynchronous communication methods, and jQuery wanted to bundle all of them into one function - named with the most common term "ajax".
However, the term "ajax" is closely linked to the XMLHTTPRequest
interface, which is limited by the same-origin-policy. While this one does not apply to JSONP, which uses <script>
elements, JSONP is limited to GET-requests and needs a special serverside infrastructure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With