search

<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);

}
?>

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools