我使用AJAX post方法将以下值成功传递到我的PHP文件
[{
"name": "Apple",
"category": "Fruit",
"description": "This is my dummy descriptionss Nut.",
"tier" : "t1",
"all" : "vall",
"count":"2"
}, {
"name": "Pear",
"category": "Fruit",
"description": "This is my dummy descriptionss Nut.",
"tier" : "t1",
"all" : "vall",
"count":"4"
}, {
"name": "Almond",
"category": "Nut",
"description": "This is my dummy descriptionss Fruit.",
"tier" : "t3",
"all" : "vall",
"count":"3"
}, {
"name": "Mango",
"category": "Fruit",
"description": "This is my dummy descriptionss Nut.",
"tier" : "t3",
"all" : "vall",
"count":"62"
}, {
"name": "Cashew",
"category": "Nut",
"description": "This is my dummy descriptionss Fruit.",
"tier" : "t2",
"all" : "vall",
"count":"99"
}]
问题是以下代码发送name:John
email:test@test.com
comments:Hello
category_list[]:Books
category_list[]:Documents
而不是HelloArray
。你能不能帮我找到我的错误。
HelloBooksDocuments
答案 0 :(得分:2)
替换此行:
$comments= $comments.$categories;
使用:
$comments= $comments.implode("", $categories);
原因是变量 $ categories 是一个数组,您需要将其转换为字符串。
您可以使用implode。如果你想用逗号分隔它们,那么把它作为第一个参数传递,替换我上面建议的空字符串“”。
当然,您可以更改此设置,并使用您选择的其他分隔符。