Javascript-Cross-origin Data Retrieval

Source: Internet
Author: User
When reading data from your server, you cannot obtain the data from the following external sources, and add the header (& #039; content-type: application: json; charsetutf8 & #039;); header (& #039; access-Control-Allow-Origin: * & #039;); header (& #039; Access-Control-Allow-Methods: POST & #039 ;); header (...

When reading data from your own server

Data cannot be obtained externally.
Header ('content-type: application: json; charset = utf8 ');
Header ('access-Control-Allow-Origin :*');
Header ('access-Control-Allow-Methods: Post ');
Header ('access-Control-Allow-Headers: x-requested-with, content-type ');
After

Why are the following results in json format different from those received?

Reply content:

When reading data from your own server

Data cannot be obtained externally.
Header ('content-type: application: json; charset = utf8 ');
Header ('access-Control-Allow-Origin :*');
Header ('access-Control-Allow-Methods: Post ');
Header ('access-Control-Allow-Headers: x-requested-with, content-type ');
After

Why are the following results in json format different from those received?

Jsonp for cross-origin Data Retrieval

It is clearly written that an array containing two elements and the data passed throughJSON.strigify()AndJSON.parse()Can be converted to each other.

... Special interfaces are required for cross-origin, not any interface for returning data.
Jsonp, script, and other labels are required. The returned result is a function with parameters instead of simple data...
Between...

Of course, the json format can be an array, a string, or an object.

JSON.parse('true');JSON.parse('false');JSON.parse('1');JSON.parse('0');JSON.parse('"hello"');JSON.parse('""');JSON.parse('[]');JSON.parse('{}');

Theoretically, JSON objects can be correctly converted by json. parse. At the same time, we also need to distinguish what is a json string and what is a json object.

header('content-type:application:json;charset=utf8');
The browser directly parses the result as json.

One is a string and the other is json, so there is no difference... just convert it.

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.