Home > Web Front-end > JS Tutorial > body text

Example of php cross-domain calling json_jquery

WBOY
Release: 2016-05-16 17:15:41
Original
1255 people have browsed it

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

Copy code The code is as follows:



The adjusted file profile.php
Copy Code The code is as follows:

$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.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!