Home > Backend Development > PHP Tutorial > A comprehensive example of jQuery/Ajax/PHP/Json_PHP tutorial

A comprehensive example of jQuery/Ajax/PHP/Json_PHP tutorial

WBOY
Release: 2016-07-13 17:49:08
Original
917 people have browsed it

jQuery is an excellent Javascript framework that provides excellent packaging for js and provides many convenient functions. jQuery's packaging of ajax is also excellent.

jQuery can transmit data using the json file transfer protocol (similar to xml, and has a tendency to replace xml), and the website backend code must be used in conjunction with it. PHP uses the json_encode function to encode the returned array data, but this function is only supported by PHP version 5.2 or above.

I found a json operation class from the Internet, and I tested it under PHP4.4.7 version. I also built a function function my_json_encode($phparr) to make the code compatible with PHP5.2 and above.

Sample code (including json class package software) can be downloaded at the following URL: http://www.BkJia.com/uploadfile/2012/0221/20120221090101730.rar


The following is the full code:



jQuery Ajax Demonstration



 
 
 
 
 
   

输入姓名:

 
   

输入年龄:

 
   

输入性别:

 
   

输入工作:

 
 
 
 
 
 
 
 
 
 
PHP 文件 ajax_json.php: 
 
//$arr = $_POST; //若以$.get()方式发送数据,则要改成$_GET.或者干脆:$_REQUEST  
$arr = $_REQUEST; 
$arr['append'] = '测试字符串'; 
//print_r($arr);  
$myjson = my_json_encode($arr); 
echo $myjson; 
 
function my_json_encode($phparr) 

    if(function_exists("json_encode")) 
    { 
      return json_encode($phparr); 
    } 
    else 
    { 
      require_once 'json/json.class.php'; 
      $json = new Services_JSON; 
      return $json->encode($phparr); 
    } 

?> 

摘自 chaojie2009的专栏

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/478373.htmlTechArticlejQuery 是一个优秀的 Javascript 框架,对 js 进行了优秀的包装,提供了许多方便的功能。jQuery 对 ajax 的包装也堪称优秀。 jQuery 可以以 json 文件...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template