Ajax cross-domain call implementation code using jQuery in PHP

WBOY
Release: 2016-07-29 08:48:08
Original
1202 people have browsed it

You can define a calling method on the page, as follows:

Copy code The code is as follows:


function getData(){
$.getJSON("http://123.123.123.123/?callback=?",
{
"m": "data", // Specify the file name of php
"act": "getdata", // Specify the method in the php file
"name": "Problem Child" // Incoming parameters
},
function(data) {
// Get the return value
}
});
}


corresponds to the PHP file under the link (123.123.123.123). Generally, the index.php file is called first by default, through index.php After the methods in the file are processed, go to the corresponding php file, find the corresponding method, and execute it.
index.php code is as follows:

Copy code The code is as follows:


/**
* Entry file
*/
$string = $_SERVER["REQUEST_URI"];// Get access The url
$m = get_m($string);
$file_path = "app/".$m.".php";
define('IS_INDEX',true);// Prevent direct access to the app directory
require ($ file_path);
/**
*
* Get access to php file
* @param string $url
*/
function get_m($url){
$strings = explode('m=', $url);
$res = explode("&", $strings[1] ;

/**
* data file

*/
$act = !empty($_GET['act']) ? $_GET['act'] : '';
if ($act == ' getdata')

{ $name = "My name is:".$_REQUEST['name']; echo $_REQUEST["callback"]."(".json_encode($name).")"; } ?>


After successful call, the screen can get the returned json data.
The above introduces the ajax cross-domain call implementation code using jQuery in PHP, including the ajax cross-domain content. I hope it will be helpful to friends who are interested in PHP tutorials.


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!