JSONP-My _ json-js tutorial

Source: Internet
Author: User
This article mainly introduces my personal understanding of jsonp, the concept of jsonp, cross-domain issues, and the differences between jsonp and XMLHttpRequest. As I am a beginner of javascript, it is inevitable that I will have some improper features, please correct me. Thank you. I am a beginner in JavaScript. I have some understanding. please correct me if you have any mistakes ~

JSONP:

The method used to obtain xxx website (cross-origin) data from a local html file.

Cross-origin problems:

Data on the external server can only be accessed by js on the external server, while that on the local js cannot be accessed by XMLHttpRequest.

The Web Service in the external server provides JSON data, for example, in response?

1. view the Web Service documentation and specify the actual parameter names used by the Service (in this example, only one parameter is an object array );
2, specify a callback function in the url, http://gumball.wickedlysmart.com /? Callback = updateSales, used to specify the name of the function used to access JSON data in the Web service;
3. Create the function updateSales (object) using the function name just defined in the local js file and write a method for processing the external JSON data;
4. In the html fileUse the script label under the tag to link to the external Web service. The url is the path in 2.

Summary:

JSONP aims to provide a function interface for the local html (the local html can be added after the url? Callback = functionName). To ensure data access security, the server places the safe data in the callback function parameters, the internal parameter of the function is the data that the server provides to the local machine. The callback function must be defined in the local js for how to use the data.

Note: If you use JSONP locally to request access to the Web service, you may obtain insecure Js Code. Therefore, ensure that you trust this Web service.

JSONP and XMLHttpRequest:

XMLHttpRequest is used to develop internal Web Services. Internal access is easier to access in the same domain.

JSONP is required when accessing external data (cross-origin access.

The above is all the content of this article. I hope you will like it and it will help you learn jsonp.

Related Article

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.