gpt4 book ai didi

javascript - jQuery ajax 不发送数组

转载 作者:行者123 更新时间:2023-11-30 18:02:56 25 4
gpt4 key购买 nike

我试图通过 AJAX 发送数组中的一些数据以将其保存到数据库,我以这种方式构建数组:

$( "#saveordering" ).button().click(function( event ) {
event.preventDefault();

var data = document.getElementById('tabs');
var categories = data.getElementsByTagName("div");
var categoryArray = new Array();

for (var i=0; i < categories.length; i++) { //Loop door de categoriëen
var category = categories[i];
var categoryId = category.getAttribute('id');

categoryArray[i] = new Array();

categoryArray[i]['id'] = categoryId;
categoryArray[i]['forums'] = new Array();

var forums = category.getElementsByTagName("li");
for (var j=0; j < forums.length; j++) { //Loop door de forums
var forum = forums[j];
var forumId = forum.getAttribute('id');
categoryArray[i]['forums'][j] = new Array();
categoryArray[i]['forums'][j]['id'] = forumId;
}
}
$.ajax({
type: 'POST',
url: "ajax/updateboardorder.php",
dataType: 'json',
data: {ldelim}"categories" : categoryArray{rdelim} ,
success: function(data) {
}
});
});

但没有发送任何内容,当我在 PHP 中执行 var_dump($_POST) 时,我得到:

array (size=0) empty

我做错了什么?

最佳答案

看这段代码

categoryArray[i] = new Array();
categoryArray[i]['id'] = categoryId;
categoryArray[i]['forums'**strong text**

嗯,那不是“数组”,你在做一个关联数组

categoryArray[i] = {};
categoryArray[i]['id'] = categoryId;
categoryArray[i]['forums'] = {};

categoryArray[i] = {
"id" : categoryId,
"forums" : {}
};

你想要一个对象。与您稍后在代码中使用 forums 执行此操作的位置相同。

关于javascript - jQuery ajax 不发送数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16468795/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com