Home > Article > Backend Development > Simple implementation of php and ajax
Step 1. Create a new folder: js and put the latest jquery.js in it.
Step 2. Create a new file mygetjson.php, the content of which is
class custom_json {
/**
* Convert array to javascript object/array
* @param array $array the array
* @return string
*/ determine type
); isset($array[$i]); ++$i) {
$ OUTPUT. = Self :: _ Val ($ array [$ i]);
if ($ i! == $ last) $ OUTPUT. = ','; else {
’ each($array as $key => $value) {
$output .= '"'.$key.'":'; $output .= ($value);
return $output;
}
/**
* [INTERNAL] Format value
* @param mixed $val the value
* @return string
*/
private static function _val($val)
{
if(is_string($val)) return '"'.rawurlencode($val).'" ';
elseif(is_int($val)) return sprintf('%d', $val);
using using using using using using out out out out out out out out of ‐ ‐ ‐ ‐ ‐‐‐‐‐‐‐‐‐ ‐ val)) return ($val ? 'true' : 'false');
‐‐'''' return 'null'';
$big_test = array(
array(
'name' => array('John', 'Smith'),
using using using using ‐ > 180.53,
‘is_human’ => true,
'string' => 'Hello',
),
array(
' 'name' => array('Green', 'Alien'),
'age' => 642,
'sex' => null,
use use using ’ s ’ s ’ s ’ to to come ‐ to
//echo custom_json:: encode($big_test);//This is used to test whether it returns json data
echo $_GET['jsoncallback'].'('.custom_json::encode($big_test).')';//Use a The callback returns
?>
Step 3. Create a new test page test.html with the content
name:' +controlinfo.name+'& lt;/p & gt;';
$ ('#info'). html (infohtml);
}
}}}); & lt ;/head>