weixin_33725272 2014-04-02 11:16 采纳率: 0%
浏览 42

AJAX传递变量问题

Hi all Im trying to pass form data and an additional variable using an AJAX call as seen below:

function tempFunction(obj) {
    var data = $('form').serializeArray();
    data.push(
        {
            no: $(obj).attr('id')
        }
    );

    $.ajax({
        type: "POST",
        url: "/tempproject/main/changepage",
        data: data,
        success: function (msg) {
            alert(msg);
        }
    });
}

however in PHP when I try and call back the 'no' variable I am getting an error saying undefined index. within my php file I am trying:

$test  = $_POST['no'];
echo $test;

when clicking I receive a popup that says undefined index no.

  • 写回答

3条回答 默认 最新

  • weixin_33690367 2014-04-02 11:25
    关注

    Each element of the array is an object with a name and value property:

    Try like this:

    data.push({name: 'no', value: $(obj).attr('id')});
    
    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题