Background profile.php Code:
Copy CodeThe code is as follows:
$arr = Array (
' FirstName ' = iconv (' gb2312 ', ' utf-8 ', ' Non-Prudential '),
' LastName ' = Iconv (' gb2312 ', ' utf-8 ', ' Don't Disturb '),
' Contact ' = = Array (
' Email ' = ' fcwr@jb51.net ',
' website ' = ' http://www.jb51.net ',
)
);
Adds an array JSON
$json _string = Json_encode ($arr);
Note here that double quotation marks can be processed on variables that are inside, and single quotes do not
echo "GetProfile ($json _string)";
?>
It should be pointed out that under the non-UTF-8 encoding, the Chinese characters will not be encode, the result will be null, so if you use gb2312 to write PHP code, then you need to use the content of the language containing iconv or MB to UTF-8 and then Json_encode.
Front desk index.html Code:
Copy CodeThe code is as follows:
The JSON format of the data directly assigned to the variables in JavaScript, it becomes an array, the next operation will be very convenient, here if the use of XML as data transmission, the subsequent operation is not convenient.
Obviously, when Index.html calls Profile.php, the JSON string is generated and passed in as a parameter to the GetProfile, and the nickname is inserted into the div so that the cross-domain data interaction is completed
Call index.html
Output: Non-prudential
http://www.bkjia.com/PHPjc/324630.html www.bkjia.com true http://www.bkjia.com/PHPjc/324630.html techarticle background profile.php Code: Copy code code as follows: PHP $arr = Array (' FirstName ' = iconv (' gb2312 ', ' utf-8 ', ' Non-Prudential '), ' lastname ' = Iconv (' gb231 2 ', ' utf-8 ', ' Do Not Disturb '), ' contact ' ...