Php code for cross-origin data transmission using JSON. Background profile. php code: Copy the code as follows :? Php $ arrarray (firstnameiconv (gb2312, UTF-8, not sincere), lastnameiconv (gb2312, UTF-8, do not disturb), contact the background profile. php code:
The code is as follows:
$ Arr = array (
'Firstname' => iconv ('gb2312', 'utf-8', 'sincerity '),
'Lastname' => iconv ('gb2312', 'utf-8', 'Do Not Disturb '),
'Contact '=> array (
'Email '=> 'fcwr @ jb51.net ',
'Website' => 'http: // www.jb51.net ',
)
);
// JSON
$ Json_string = json_encode ($ arr );
// Note that double quotation marks can be used to process the variables in the variable.
Echo "getProfile ($ json_string )";
?>
It should be noted that, in non-UTF-8 encoding, Chinese characters will not be encode, the results will be null, so if you use gb2312 to write PHP code, then we need to use iconv or mb to convert the content containing Chinese characters into UTF-8 and then perform json_encode.
Front index.html code:
The code is as follows: