我想使用Jquery向php发布一个数组。这有可能吗?
谢谢
编辑:
我试过以下几点:
type: "POST",
url: "path",
data: "styles=" + strstyles + "&templateId=" + custTempId, //strstyles is an associative array
dataType: "json",
success: function (data) { .....}
但是,样式不包含数据。在向声明中添加数据类型之前,我花了很多时间。“样式”被张贴为null的原因是什么?
第二版
我希望发布样式表dom对象,并将类名和属性保存到DB中。使用上面的编辑,添加数据类型没有帮助。我认为是b‘z,因为字符串不是json格式的,如下所示-
{"a":1,"b":2,"c":3,"d":4,"e":5}
因为我的字符串有双引号,它没有遵循格式,我想这就是原因,我得到了一个空数组。我该怎么处理呢?
发布于 2010-08-27 00:46:15
您也可以使用以下方法
$.ajax({
type: "POST",
url: location.href,
data: ({'data[]' : array}),//array is array
dataType: "json",
success : function () {
// Something after success
}
});
发布于 2010-08-27 00:49:49
如果不想使用JSON,PHP可以自动创建来自Html窗体的数组,这样就可以执行如下操作:
type: "POST",
url: "path",
data: "styles[key1]=" + strstyles.val1 + "&styles[key2]=" + strstyles.val2 + ... + "&templateId=" + custTempId
...
也就是说,如果您希望在php中有一个关联数组,但是如果您只想要一个数组,则可以这样做。
data: "styles[]=" + strstyles.val1 + "&templateId=" + custTempId
发布于 2010-08-27 01:34:00
在POST call中,您不使用&,所以您的代码应该类似于
type: "POST",
url: "path",
data: {styles: strstyles , templateId: custTempId}, //strstyles is an associative array
dataType: "json",
success: function (data) { .....}
这点明白吗?所以说到我的解决方案
var strstylesOBJ = {};
strstyles
数组插入到strstylesOBJ
中,并将其字符串化,然后在post调用中传递给它。
strstylesOBJ.styles =斯特斯特斯;斯特斯特斯= JSON.stringify(strstylesOBJ);$strstyles = json_decode($_POST['styles']);
重构数组var_dump($strstyles)
,并请告诉什么是输出。问候
阿亚兹·阿拉维
https://stackoverflow.com/questions/3582362
复制相似问题