在此我将值发送到adduser.php,执行完成后插入的id将发送到index.php。请给出评论
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;
联系.php
此响应 id 可以是下一页 url 的用户,如 window.location.href="contact.php?id=$id";
如果有任何其他选项将 id 值传递给联系人.php
最佳答案
AJAX 请求中的回调接收响应作为参数,试试这个:
$.ajax({
type: "POST",
url: "adduser.php",
data: "name="+ name +"&email="+ email,
success: function(usrid){
window.location.href="contact.php?id="+usrid;
}
})
adduser.php 中的零是不必要的。
关于javascript - 如何从ajax获取发送响应到脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36866848/