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 php file name
"act":"getdata ", // Specify the method in the php file
"name": "Problem Child" // Incoming parameters
},
function(data) {
// Get the return value
}
});
}
The PHP file corresponding to the link (123.123.123.123) generally calls the index.php file first by default, through the method in the index.php file After processing, go to the corresponding php file, find the corresponding method, and execute it.
index.php code is as follows:
Copy code Code is as follows:
/* *
* Entry file
*/
$string = $_SERVER["REQUEST_URI"];// Get the accessed 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]);
return empty($res [0])?'index':$res[0];
}
?>
data.php code is as follows:
Copy code The code is as follows:
/**
* data file
*/
$act = !empty($_GET[' act']) ? $_GET['act'] : '';
if ($act == 'getdata')
{
$name = "My name is:".$_REQUEST[ 'name'];
echo $_REQUEST["callback"]."(".json_encode($name).")";
}
?>
After a successful call, the screen can obtain the returned json data.
http://www.bkjia.com/PHPjc/325148.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325148.htmlTechArticleYou can define a calling method on the page, as follows: Copy the code as follows: function getData(){ $.getJSON( "http://123.123.123.123/?callback=?", { "m":"data",//Specify the file name of php...