A preliminary understanding of JSONP

Source: Internet
Author: User

Everyone should have heard that JSONP is a solution for "cross-domain".

So, what do we call cross-domain first? I think Baidu to explain is not accurate, from the current site to different sites (protocol, domain name, port any one or more different) of the request is called cross-domain, also for the requested Party, from different sites (and the current site of the corresponding protocol, domain name, port any one or more different) is called cross-domain request, I think this place only emphasizes the different sites, but ignores the "request" type.

In fact, from the script or other non-browser issued cross-domain request cross-domain, can be called cross-domain, such as the JS code in the cross-domain XMLHttpRequest request, and the browser issued by ordinary, regular HTTP requests, there is no cross-domain said, I am the site outside the chain other sites image links, Also called cross-domain requests, is it necessary to disallow by default? This is completely incompatible with the development philosophy of Web applications.

So I think that cross-domain should refer to unconventional HTTP requests. And the JSONP request is just ordinary regular HTTP request, with you in the browser address bar to knock the URL or form post data is the same type, but the server side of the output is a bit of a doorway. What kind of doorway is it?

The specified page or handler on the server side receives a JSONP request (in fact, a normal HTTP request) that outputs a text (containing the result data or parameters processed by the server), which is then returned to the requester and rendered to the requester's reference request (such as a script snippet), and this text, In the requester's rendering, exactly is valid, can run a piece of code, so, the request is convenient to successfully fetch the server-side data. Often hear the callback parameter, is to tell the server side, output text, the value of this parameter as a function name formatted output to the return text (string).

Speaking of which, I think you should understand, yes, it is simply a form of the API, where is what cross-domain. Clearly is a protocol, the microblog API supports such a protocol. can provide JSONP service, in fact its interface is also open (of course, you need to register, fill in a valid domain name, send you token, etc.), not to say that JSONP is a necessary and effective "technology." Alas.. Why not just engage in web APIs like this?

A preliminary understanding of JSONP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.