weixin_33691817 2016-07-14 18:56 采纳率: 0%
浏览 5

将$ _GET传递给脚本(AJAX)

I would like to pass $recptid = $_GET['id']; To the following

<div id="result"></div>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('#name').focus();
        $('#name').keypress(function(event) {
            var key = (event.keyCode ? event.keyCode : event.which);
            if (key == 13) {
                var info = $('#name').val();
                                    $.ajax({
                    method: "POST",

                    //need to pass my get variable  
                    url: "message_action.php",
                    data: {name: info},
                    success: function(status) {
                        $('#result').append(status);
                        $('#name').val('');
                    }
                });
            };
        });
    });
</script>

Which then executes message_action.php query's as at the moment my error is Undefined variable: recptid . As my query cannot access it due to been in separate file for AJAX

How can I pass $recptid to message_action.php please?

  • 写回答

3条回答 默认 最新

  • weixin_33720452 2016-07-14 19:02
    关注

    in your data: {name: info}, just put the thing too.. data: {name: info, recptid: '<?php echo $_GET["id"]; ?>'}, then in message_action.php just use $_POST['recptid']; (use post since your AJAX Call uses POST method)

    评论

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)