Backend profile.php code:
Copy code The code is as follows:
$arr = array(
'firstname' => iconv('gb2312', 'utf-8', 'Not sincere'),
'lastname' => iconv('gb2312', 'utf-8', 'No '),
'contact' => array(
'email' =>'fcwr@jb51.net',
'website' =>'http://www.jb51. net',
)
);
//Convert an array to JSON
$json_string = json_encode($arr);
//Note here that double quotes can be used as variables inside Variables are processed, single quotes will not Characters will not be encoded, and the result will be a null value. Therefore, if you use gb2312 to write PHP code, you need to use iconv or mb to convert the Chinese content to UTF-8 and then perform json_encode.
Front index.html code:
Copy code
The code is as follows:
Assign the data in JSON format directly to variables in javascript, and it will become an array. It will be very convenient to operate. , if XML is used as data transmission here, subsequent operations will be inconvenient.
Obviously, when index.html calls profile.php, a JSON string is generated and passed to getProfile as a parameter, and then the nickname is inserted into the div. In this way, a cross-domain data interaction is completed
Calling index .html
Output: Feicheng
http://www.bkjia.com/PHPjc/324630.html
www.bkjia.com
truehttp: //www.bkjia.com/PHPjc/324630.htmlTechArticleBackend profile.php code: Copy the code as follows: ?php $arr = array( 'firstname' = iconv( 'gb2312', 'utf-8', 'Not sincere'), 'lastname' = iconv('gb2312', 'utf-8', 'Do Not Disturb'), 'contact'...