2016-04-26 108 views
0

在此我發送的值adduser.php並執行完畢後插入ID將發送給index.php.please給予意見如何從AJAX發送響應腳本

的index.php

$.ajax({ 
       type: "POST", 
       url: "adduser.php", 
       data: "name="+ name +"&email="+ email, 
       success: function(msg,usrid){ 
       alert(msg); 
} 
}) 

adduser.php

$q = mysql_query("INSERT INTO `user_login`(fname,email) VALUES('$fname','$email')"); 
    $id=mysql_insert_id(); 
echo '0'; 
echo $id; 

contact.php

此響應ID CA n爲用戶的下一個頁面的url像window.location.href="contact.php?id=$id";是否有任何其他選項傳遞的id值來contact.php

+2

你的問題是什麼? –

+1

你爲什麼回聲'0'; there –

+0

我想發送adduser.php頁面$ id值到contact.php – Nandhakumar

回答

1

在AJAX請求回調接受作爲參數的反應,試試這個:

$.ajax({ 
      type: "POST", 
      url: "adduser.php", 
      data: "name="+ name +"&email="+ email, 
      success: function(usrid){ 
        window.location.href="contact.php?id="+usrid; 
       } 
}) 

的在您的adduser.php零是不必要的。

+1

謝謝@Jose Rojas..it工作正常 – Nandhakumar

+0

我怎樣才能得到兩個函數變量的值如成功:function(usrid,email){ window.location.href =「contact.php?id =「+ usrid; } – Nandhakumar

+0

在服務器端的響應中,您可以將數據作爲數組編碼回顯爲JSON,這樣您可以根據需要從服務器獲取儘可能多的變量,例如'echo json_encode(array('usrid'=> 1, 'foo'=>'bar'));'在客戶端,你可以獲得這個值'success:function(response){response.usrid; response.foo}' –