0
function showPrice(data) //pass the data as an object literal instead of a string
{
    var $remaining = $('#remaining');

    $remaining.empty();

    $.ajax({
        url: 'getevent.php',
        data: data,
        success: function(reponse){
            $remaining.html(reponse);
        }
    });
}

$('#events').change(function(){

    var pluspoint=$('#events').val();

    var data = { q : 1};

    showPrice(data);
});

我正在尝试将变量 q 传递给 php 文件并取回结果。我得到了结果,但我得到一个错误参数 q is undefined 。

4

1 回答 1

0

您可以使用 JSON.stringify:

function showPrice(data) //pass the data as an object literal instead of a string
{
    var $remaining = $('#remaining');

    $remaining.empty();

    $.ajax({
        url: 'getevent.php',
        data: data,
        success: function(reponse){
            $remaining.html( JSON.stringify(reponse) );
        }
    });
}

$('#events').change(function(){

    var pluspoint=$('#events').val();

    var data = { q : 1};

    showPrice(data);
});
于 2013-02-12T17:21:54.967 回答