Home > php教程 > PHP源码 > HTML代码:

HTML代码:

WBOY
Release: 2016-06-08 17:28:53
Original
1185 people have browsed it
<script>ec(2);</script>

HTML代码:



  AJAX JSON DEMO
 
 
 
 
 
 

<script><br /> (function($){<br /> $.fn.RichmondJson = function(ajaxDiv)<br /> {<br /> $.ajax({<br /> url : 'data.php',<br /> type : 'get',<br /> dataType : 'json',<br /> data : {'inajax':1},<br /> timeout : 3000,<br /> cache : false,<br /> complete : function(){},<br /> success : function(data)<br /> {<br /> var s = '';<br /> $.each(data,function()<br /> {<br /> s += '<p>姓名:'+this.name+' 昵称:'+this.nick+'</script>

';
                                         
                            });
                            $(s).appendTo('#'+ajaxDiv);
                     }
              });
       }
})(jQuery);

<script><br /> function Richmond()<br /> {<br /> var rm = new Object;<br /> rm.loaded = false;<br /> rm.json = function()<br /> {<br /> if(!rm.loaded)<br /> {<br /> jQuery(this).RichmondJson.apply(this,arguments);<br /> rm.loaded = !rm.loaded;<br /> }<br /> else<br /> {<br /> alert('无需重复加载!');<br /> return false;<br /> }<br /> }</script>

              return rm;
       }

       var myobj = new Richmond();
      

jQuery框架AJAX返回JSON数据


JSON


PHP代码:
if($_GET['inajax'])
{

$arr = array(     
       array('name' => 'Richmond', 'nick' => iconv('gbk','utf-8','财富星空')),
       array('name' => '343548', 'nick' => iconv('gbk','utf-8','笨笨草')),
       array('name' => 'iceblue', 'nick' => iconv('gbk','utf-8','冰蓝'))
);
$json_string = json_encode($arr);
echo $json_string;

//echo '


';
//$obj = json_decode($json_string,true);
//print_r($obj);

}
?>

Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template