json.html
<script type="text/javascript" src="jquery.js"></script> <script> $(function(){ $.getJSON("test.php","name=john&sex=boy", function(json){ //$.getJSON("test.php?name=john&sex=boy", function(json) //$.getJSON("test.php",{name: "John", sex: "boy"}, function(json) $("#name").val(json.name); $("#sex").val(json.sex); }); }); </script> <div id="OK"></div> name:<input id="name" type="text"/><br/> sex:<input id="sex" type="text"/></a><br/>
test.php
<?php $name=$_GET[name]; $sex=$_GET[sex]; $list=array("name"=>$name,"sex"=>$sex); echo $encode= json_encode($list);
ajax
$.ajax({ type:'POST', url:'chk.php?username=' + username, data:'', success:function(obj){ if(obj == '1'){ return false; } else{ return true; } } });
chk.php
$username = $_REQUEST['username']; if ($username=="hello") { echo "1"; }else{ echo '0'; }