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
Ïà¹ØÎĵµ£º
ÔÎÄÁ´½Ó£ºhttp://www.phpdo.net/index.php/2010/02/03/1-10/
ÓëÆäËû±à³ÌÓïÑÔ²»Í¬µÄÊÇ£ºPHPµÄÊý¾ÝÀàÐͲ»ÊÇÓɳÌÐòÔ±ÔÚ¶¨Òå±äÁ¿µÄʱºò¾ö¶¨µÄ£¬¶øÊÇÓÉPHPÔÚ³ÌÐòÔËÐйý³ÌÖж¨Òå¡£
PHP¹²Ö§³Ö8ÖÖÊý¾ÝÀàÐÍ£ºÕûÐÍ£¨integer£©¡¢¸¡µãÐÍ£¨float£©¡¢×Ö·û´®ÐÍ£¨string£©ºÍ²¼¶ûÐÍ£¨Boolean£©ËÄÖÖ±êÁ¿ÀàÐÍ£¬Êý×飨array£©ºÍ¶ÔÏó£¨object£ ......
jQuery Ajax È«½âÎö
±¾ÎĶÌÖ·£ºhttp://s8.hk/0itq
<!--
.ajax div{
border: solid 1px red;
}
-->
// <![CDATA[
$(function(){
$("#btnajax").click(function(){
$.ajax({
type: "get",
url: "/rss",
beforeSend: function(XMLHttpRequ ......
³õѧJQUERY AJAXʹÓ㬲»ÖªµÀÔõôʵÏÖ£¬ÕÒÁ˰ëÌì×ÊÁ϶¼²î²»¶à£¬¿ÉÊǷŵ½ÎÒµÄÒ³ÃæÀï¾ÍÊDz»·µ»ØÖµ£¬ºóÀ´·¢ÏÖÒòΪûÍùºóÌ¨Ò³Ãæ´«ÖµµÄÔÒò£¬¼ÓÁË data: "name=John&location=Boston"¾ÍºÃÓÃÁË£¬ÕâÀïdata:""¿ÉΪÈÎÒâÖµ£¬ºǫ́²¢Ã»ÓнÓÊÕ¡£
ÏÂÃæÊÇÀý×Ó£¬ÊµÏÖµÄÊÇ»ñÈ¡·þÎñÆ÷ʱ¼ä²¢¸üÐÂ
ǰ̨´úÂ룺
function getServerTi ......
AJAX
AJAXÈ«³ÆÎª“Asynchronous JavaScript and XML”£¨Òì²½JavaScriptºÍXML£©£¬ÊÇÖ¸Ò»ÖÖ´´½¨½»»¥Ê½ÍøÒ³Ó¦ÓõÄÍøÒ³¿ª·¢¼¼Êõ¡£ËüÓлúµØ°üº¬ÁËÒÔϼ¸ÖÖ¼¼Êõ£º
Ajax£¨Asynchronous JavaScript + XML£©µÄ¶¨Òå
»ùÓÚweb±ê×¼£¨standards-based presentation£©XHTML+CSSµÄ±íʾ£»
ʹÓà DOM£¨Document Object Model£© ......
À´Ô´ÓÚ£ºhttp://news.csdn.net/a/20100205/216909.html
¾Ý¡¶Å¦Ô¼Ê±±¨¡·ÍøÕ¾±¨µÀ
£¬¶ÁÐ´Íø¼ÇÕßÓëPHPµÄ´´ÔìÕßRasmus LerdorfÁªÏµ£¬Ñ¯ÎÊËû¶ÔFacebook¸Õ¸Õ¿ªÔ´µÄPHPÓÅ»¯ÏîÄ¿HipHopÓкο´·¨¡£LerdorfÔÚÓʼþÖÐ˵£¬ÕâÊÇÒ»¸öºÜ¿áµÄÏîÄ¿£¬¿Ï¶¨»á³ÉÎªÄ³Ð©ÍøÕ¾ºÜºÃµÄÑ¡Ôñ¡£
µ«ÊÇ£¬Ëû½ÓÏÂÀ´Ëµ£¬¶ÔÓÚÐí¶àWebÓ¦ÓÃÀ´Ëµ£¬Ö´ÐÐËٶȲ¢²»ÊÇÖ ......