喵-见缝插针 2019-01-18 11:17 采纳率: 0%
浏览 18

AJAX数据捕获

File Name: first.php

<th><button type="button" id= "pre_production" class="btn submit_button" value = <?php echo $_REQUEST["project"] ;?>><b>PRE PRODUCTION</b></button></th>

I am sending the button value to second page through AJAX

$("#pre_production").click(function()
    {
        var data_pre_production = $("#pre_production").val();
        $.ajax({
                type:"POST",
                url:"second.php",
                data:{data_pre_production},
                success:function(data){
                    //alert(data);
                }
            });
    });

In the second page I am trying to capture the button value like

Welcome Home

BUt it is showing the error like "Undefined index data_pre_production"

Please help to solve this problem..thanks

  • 写回答

1条回答 默认 最新

  • weixin_33743248 2019-01-18 11:19
    关注

    When you are creating the parameters the AJAX sends to the PHP you need to give the parameter a name and a value. The parameter name will be what you use to access that data from $_POST, $_GET or $_REQUEST as you appear to be using

    data:{data_pre_production: data_pre_production},
    

    Or maybe in this case it should be

    data:{project: data_pre_production},
    
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?