繁体   English   中英

通过ajax将数组传递给php

[英]Passing array to php through ajax

我在页面上显示了一系列不同类型的文章。 您可以选中或取消选中这些类型,以使其在商品生成程序中显示/隐藏。 使用我当前在jquery中创建的数组生成器,它无法通过ajax正确传递给php中的$ _POST。

每次未选中/选中复选框时触发的我的函数

$(".jquery-checkbox").change(function(){
    var data = new Array();

   //check all the different types and see if they are checked or not
    $(".jquery-checkbox").each(function() {
        //if the type is not checked, put it into the data array to filter from results
        if(!$(this).is(':checked')){
            data[$(this).attr("name")] = $(this).attr("name");
        }
    });

    $.ajax({
            type: "POST",
            url: "/Ajax/article/articleList.php",
            dataType: "html",
            data: data,
            success: function(data) {$("#article-spawner").html(data);},
            error: function(){return false;}
    });
});

有没有我可以找到未选中的每种类型,并将它们以这种形式放入数组中:

        var data = {
                "8":"not-checked",
                "10":"not-checked"
        };

它可以与上述方法一起使用,但我不确定如何使用.each达到此方法

在JavaScript中,数组用于具有数字索引的顺序数据。 尽管您可以将所需的任何属性粘贴到它们上,但是处理它们的大多数工具都将忽略这些属性。

假定输入的名称属性像传统的一样具有非数字名称。

使用常规对象,而不是数组。

更改var data = new Array(); var data = new Object(); var data = {};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM