There is not much difference between JSON and XML, but JSON has a wider range of applications, that is, cross-domain data calls. Due to security issues, AJAX does not support cross-domain calls, so it is very troublesome to call data under different domain names. The following example is enough to show how PHP uses json to make cross-domain calls.
index.html
The adjusted file profile.php
$arr = array(
'name' => 'tanteng',
'nick' => 'pony',
'contact' => array(
'email' => 'a@gmail.com',
'website' => 'http: //aa.sinaapp.com',
)
);
$json_string = json_encode($arr);
echo "getProfile($json_string)";
?>
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. Isn’t it special? Simple.