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
}
});
}
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
{ $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.