JavaScript-Questions about cross-domain access to data
Source: Internet
Author: User
KeywordsJqueryphpjavascript
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.
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.
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.