javascript - 如何从ajax获取发送响应到脚本

标签 javascript php ajax

在此我将值发送到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/

相关文章:

javascript - 几个嵌套 div 上的 Z-index 和不透明度

javascript - 如何在 jqGrid footerData 中使用 colspan?

javascript - AngularJS - 在自定义指令中继承 ngModel

php - 为什么这个 JQuery/AJAX 调用不起作用?

jquery - 如何在Ajax请求中添加自定义 header 以进行跨域JsonP调用

javascript - 客户端重新加载页面时如何修复服务器故障?

php - 无法使更新查询工作

php - 警告:preg_replace_callback():需要参数2

PHP线程池

javascript - 为网页实现类似 "server push"行为的最简单方法是什么?