Parsing JSON Data from PHP Using jQuery (ajax)
have been studying parsing JSON from PHP using AJAX to display it in
the client side and jQuery had been a great help to me. Here is a very
simple code in parsing JSON using jQuery that i made.
tablejsondata.php
This file makes the request to a php file and displays the returned data into a table.
<html>
<head>
<title>Parsing JSON from PHP Using jQuery</title>
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript">
</script>
</head>
<body>
<a href="#" id="loaduserdata">User Data</a>
<table id="userdata" border="1">
<thead>
<th>First Name</th>
<th>Last Name</th>
<th>Email Address</th>
<th>City</th>
</thead>
<tbody></tbody>
</table>
<script>
$(document).ready(function(){
});
$("#loaduserdata").click(function(){
$("#userdata tbody").html("");
$.getJSON(
"jsondata
.php
",
function(data){
$.each(data.userdata, function(i,user){
var tblRow =
"<tr>"
+"<td>"+user.first+"</td>"
+"<td>"+user.last+"</td>"
+"<td>"+user.email+"</td>"
+"<td>"+user.city+"</td>"
+"</tr>"
$(tblRow).appendTo("#userdata tbody");
});
}
);
});
</script>
</body>
</html>
jsondata.php
This is the file that contains the JSON data.
<?php
$json = '{
"userdata": [
{
"first":"Ciaran",
"last":"Huber",
"email":"elementum.purus@utdolordapibus.edu",
"city":"Mayagüez"
},
{
"fi
Ïà¹ØÎĵµ£º
SimpleTestÊÇÒ»¸öʹÓÃÊ®·Ö¼òµ¥µÄµ¥Ôª²âÊÔ¹¤¾ß¡£
Ò»ÏÂÄÚÈÝÊÇÎÒ×Ô¼ºÉè¼ÆµÄÀûÓÃSimpleTest¶ÔÒ»¸öÏîÄ¿½øÐе¥Ôª²âÊԵĴúÂë
Ò»¡¢Îļþ½á¹¹
Ò»¸öÏîÄ¿Óжà¸öÎļþ¼Ð£¬Îļþ¼ÐÖл¹°üº¬Îļþ¼Ð¡£ÎÒÃÇÒª½øÐвâÊԵĴúÂë¼´°üº¬ÔÚÕâЩÎļ ......
zip.class.php
CODE:
[¸´ÖƵ½¼ôÇаå]
<?
class
zip
{
var
$datasec
,
$ctrl_dir
= array();
var
$eof_ctrl_dir
=
"x50x4bx05x06x00x00x00x00"
;
var
$old_offset
=
0
; var
$dirs
......
Ajax¿ÉÒÔʵÏÖÍøÒ³µÄ¾Ö²¿Ë¢ÐÂ,ÊÇͨ¹ýJS»ñÈ¡Êý¾Ý,ÔÙ°ÑÊý¾ÝÌí¼Óµ½ÍøÒ³ÖÐ,È»¶øÓÉÓÚä¯ÀÀÆ÷µÄ²»Í¬,³õѧÕߺÜÄÑ×öµ½¼æÈÝÎÊÌâ.
ÕâÀïÎÒÏò´ó¼Ò½éÉÜÒ»Öֺõķ½·¨.ͨ¹ýJQuery²å¼þ.JQuery.jsÎļþ¿ÉÒÔÔÚ¹ÙÍøÉÏÏÂÔØ,»òÕßgoogleÒ²ÐÐ.
Ê×ÏÈÄãÒªÔÚÍøÒ³ÒýÈëJSÎļþ
<script src="../javascript/jquery.js" type="text/javascript"></ ......
ajax.dllÒѾÊǺÜÀϵĶ«Î÷ÁË£¬µ«ÊǽñÌìÎÒ²ÅÓõ½Ëü£¬ÏÖÔÚ°ÑËüµÄʹÓ÷½·¨¼Ç¼ÏÂÀ´¡£
1.ÔÚweb.configÖÐÅäÖÃajaxµÄ´¦Àí³ÌÐò¡£
<httpHandlers>
<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
<httpHandlers>
2. ×¢²á´¦Àí³ÌÐòÀ࣬ajaxTestÊ ......
Perl¡¢PHP¡¢ASP¡¢JSP¼¼Êõ±È½Ï
±¾ÎĽ«¶ÔĿǰ×î³£ÓõÄËÄÖÖ¶¯Ì¬ÍøÒ³ÓïÑÔPerl£¨Practical Extraction and Report Language£©¡¢PHP£¨Hypertext Preprocessor£©¡¢ASP£¨Active Server Pages£©¡¢JSP£¨JavaServer Pages£©½øÐÐһЩ¼¼ÊõÐԵıȽϡ£
¡¡¡¡Perl
¡¡¡¡Perl£¨Practical Extraction and Report Language£©ÊÇÒ»ÖֺܹÅÀϵĽű ......