PHP Ajax return JSON data instance _php tutorial

Source: Internet
Author: User
This tutorial is a PHP ajax return JSON data instance, it is to take advantage of Ajax real-time to accept the json.php file sent data requests, and processed.

Http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd ">




<title></title>
PHP Tutorial Ajax return Web effects on data instance






json.php file

/**************************************************************
*
* Processing of all elements in an array using a specific function
* @param string & $array strings to be processed
* @param string $function the function to execute
* @return Boolean $apply _to_keys_also is also applied to the key
* @access Public
*
*************************************************************/
Function arrayrecursive (& $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--;
}

/**************************************************************
*
* Convert Array to JSON string (Chinese compatible)
* @param array $array to convert
* JSON string to be converted @return string
* @access Public
*
*************************************************************/
function json ($array) {
Arrayrecursive ($array, ' UrlEncode ', true);
$json = Json_encode ($array);
Return UrlDecode ($json);
}

$array = array
(
' Name ' = ' Shia ',
' Age ' =>20,
' ID ' =>$_post[' CID ']
);


echo JSON ($array);
/*********
{"Name": "Shia", "Age": "20"}

This tutorial is a PHP ajax return JSON data instance, it is to take advantage of Ajax real-time to accept the json.php file sent data requests, and processed.

Download the address for this tutorial

Http://down.php100.com/down/code/jquery/2010/0812/20181.html

* **********/
?>


http://www.bkjia.com/PHPjc/445440.html www.bkjia.com true http://www.bkjia.com/PHPjc/445440.html techarticle This tutorial is a PHP ajax return JSON data instance, it is to take advantage of Ajax real-time to accept the json.php file sent data requests, and processed. Http://www.w3.org/tr/xhtml1/dtd/ ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.