JavaScript-Questions about cross-domain access to data

Source: Internet
Author: User
Keywords Jquery php javascript

When reading your own server data, the following

External data cannot be obtained, plus
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 do you receive different results, and the following results also belong to JSON?

Reply content:

When reading your own server data, the following

External data cannot be obtained, plus
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 do you receive different results, and the following results also belong to JSON?

JSONP for data acquisition across domains

Figure 2 writes clearly is an array containing two elements, and the data in Figure 1 and Figure 2 are passed JSON.strigify() and JSON.parse() can be converted to each other.

.. A cross-domain requires a specialized interface, not a random data return interface.
Requires Jsonp,script and other labels to be completed. They expect the return to be a function. There are parameters, not simple data ...
Among the family ...

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

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

As long as the theory that can be correctly transformed by Json.parse should be counted as JSON object. Also distinguish what is a JSON string and what is a JSON object.

header('content-type:application:json;charset=utf8');
This header, the browser to the results as JSON directly parse the

One is a string, one is JSON, nothing is different ... It's the right conversion.

  • 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.