2016-04-26 78 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}' –