使用ajax发布并显示收到的数据


with ajax post and show recived data

我写了这段代码,但它不起作用。我想使用ajax在php中显示一个数组。它是一个html select,用于选择变量中选项take的select列表值中的每个选项,并将其发送到ajax。Ajax应该将数据发布到php,然后php从数据库中选择接收到的数据并显示所有数据。但我无法在ajax中显示这些数据。:(

$(function(){
    $("#topic").change(function(){
        var str = "";
        $( "select option:selected" ).each(function() {
            str += $( this ).text() + " ";
            options(str);
        });
    });
});
function options(option){
    $.ajax({
        type: "POST",
        dataType: 'json',
        url: "/Register/checkSelect", //Relative or absolute path to response.php file
        data: {
            option:option
        }).done(function(){
            $("#content").html(data);
            alert("ok");
        });
    });
}

您的ajax请求中有一个错误。这里是正确的代码:

function options(option){
        $.ajax({
                type: "POST",
                dataType: 'json',
                url: "/Register/checkSelect", //Relative or absolute path to response.php file
                data: {
                    option:option
                }
    }).done(function(data){
                 $("#content").html(data);
                 alert("ok");
   });
}