1. Back end
//dealing with problems with JSON arrays in ChinesefunctionArrayrecursive (&$array,$function,$apply _to_keys_also=false){ Static $recursive _counter= 0; if(++$recursive _counter> 1000) { die(' Possible deep recursion attack '); } foreach($array as $key=$value) { if(Is_array($value) {arrayrecursive ($array[$key],$function,$apply _to_keys_also); } Else { $array[$key] =$function($value); } if($apply _to_keys_also&&is_string($key)) { $new _key=$function($key); if($new _key!=$key) { $array[$new _key] =$array[$key]; unset($array[$key]); } } } $recursive _counter--;}
// returns a JSON array directly function JSON ($array) { arrayrecursive ($arraytrue); $json = Json_encode ($array); return UrlDecode ($json);}
// called $data Array (); $data [' Success ']= "false"; $data [' Message ']= ' username does not exist, please re-enter' ; Echo JSON ($data);
2. Front End
$.post ("Ajax.php?mod=member&code=check_user_exist", {username:username},function(data) { var json=$.parsejson (data); if (json.success) { alert (json.success); }else{ alert (json.success); } });
PHP returns a JSON array