Using JSON to implement cross domain calls of data

time:13-08-13 forum:PHP tools and code
  JSON

background profile.php Code:

[code].lt; PHP
$arr = array. X.com',
'website' =.gt;'http://www.xxx.net',
)
]

needs to be pointed out that in non UTF-8 encoding, Chinese characters will not be encode, the result will come out of the empty value, so if you use GB2312 to write PHP code, then you need to convert the contents of the Chinese with iconv or MB to UTF-8 and then json_encode.
index.html code of the front desk:

[code].lt; script type=.quot; text/javascript.quot;.Gt;
function getProfile. Quot; firstname.quot;.Gt;.Lt; /div.gt;
.lt; /body.gt;
.lt;! T;.Lt; /script.gt; [/code]

assign the JSON data directly to the variables in JavaScript and turn into an array, and the next operation will be very convenient. If XML is used as a data transfer, the subsequent operation is inconvenient.
obviously, when index.html calls profile.php, the JSON string is generated and passed into the getProfile as a parameter, and then the nickname is inserted into the div, so that the cross domain data interaction is completed.

prev:Lenovo Thinkpda R61I notebook 599 yuan next:Fourteen experiences in programming for ...
post comment
Notice



approved   Children go to school, Ji'nan addres...   Ji'nan: 27 year old girl loves croch...   The "one school one product" sports ...   These "90" in the mountains, the vil...   Chinese girls spend 4 years designin...
rand   PHP random number generation and use...   Talk about 10 MySQL mistakes that PH...   10 MySQL errors that PHP developers ...   Eliminate 3 Chinese characters from ...   Importing large databases to virtual...
ads

other

Because all the contents of this site are reproduced from other media, the intention is to provide free services to the public, but it does not mean that this site agrees with its views, and can not be responsible for the authenticity of its verification, such as the copyright unit or individual of the manuscript does not want to publish on this site, please Contact me, I will immediately remove it, thank you. Contact: atseashawk@163.com