我希望将返回的数据写入html的div标签

时间:2013-02-12 17:16:32

标签: ajax jquery

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未定义。

1 个答案:

答案 0 :(得分: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);
});