无法检索通过ajax发送的数组

时间:2018-10-17 19:02:56

标签: php jquery ajax

这是我的功能,获取所有ID的广告将它们存储在数组中,然后将其发送到php页面。使用Google Chrome浏览器网络工具,我可以看到在标头中具有数组的请求。

$(document).ready(function() {
    $("#insert_articoli").click(function(){
        var id_articoli = [];
        $.each($("input[name='articoli']:checked"), function(){
            id_articoli.push($(this).val());
        });
                    $.ajax({
                     type: "POST",
                     url: "componi_prodotto.php",
                     data: {data : id_articoli },

                     success: function(){
                             alert("OK");
                     }
             });
    });
});

我找不到从我的php页面检索此数组的方法。请帮忙。

1 个答案:

答案 0 :(得分:1)

确保您在PHP中回显了某些内容,然后需要返回一些内容,因此请在成功函数中设置一个变量:

success: function(response){ // whatever is echoed in PHP will be in 'response'
     console.log(response);
}

quit using alert() for troubleshooting.,改用console.log()

相关问题