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')});
    
    评论

报告相同问题?