header("Content-Type:text/html;charset=utf-8");
public function do_register1(){ //第三步-------------------------------------數據庫這裏處理 $map['username']=I('post.username'); $res=$this->person_model->where($map)->count(); //返還數據到ajax引擎裏面 $notice=""; if($res>0){ //這裏用notice鏈接到xml的文件內容 //$notice.="<res><mes>用戶名已經註冊!!!</mes></res>"; //這裏使用json數據傳入 $notice='{"message":"該用戶不能用,已經註冊"}'; }else{ //$notice.="<res><mes>用戶名沒有註冊,能夠用!</mes></res>"; $notice='{"message":"該用戶能用,能夠註冊"}'; } echo $notice; }
function chuli(){ //+myXmlHttpRequest.readyState //第四步------------------------------取出頁面返回的數據 if(myXmlHttpRequest.readyState==4){ //這裏使用json數據傳入這裏使用 var mes=myXmlHttpRequest.responseText;//獲取json的值 //打印出來是'{"message":"該用戶不能用,已經註冊"}'; var mes_obj=eval("("+mes+")");//實例化對象得到mes_obj對象 message做爲對象裏面的屬性便可調用 $('myres').value=mes_obj.message; } }
所有代碼能夠參考這裏
php