简体   繁体   English

Ajax Post:发布的对象数组,无法在php端检索

[英]Ajax Post : Array of Object posted , not able to retrieve in php side

"company=1&cat=3&cat=1" “公司= 1&猫= 3&猫= 1”

my Javascript object "cat" have two values 1,3 and 我的Javascript对象“ cat”有两个值1,3和

var cat = [];
cat.push(1);
cat.push(2);

now i want post it to servr using AJAX , I am able to post the data 现在我想使用AJAX将其发布到servr,我可以发布数据

and I can see data appearing in PHP side but my problem is 我可以看到数据出现在PHP端,但是我的问题是

when I capture posted data in php it is only showing one value of cat 当我在php中捕获发布的数据时,它仅显示cat的一个值

actual data = company=1 , cat= [1,3]; 实际数据=公司= 1,类别= [1,3];

here is my posted query = company=1&cat=3 这是我发布的查询= company = 1&cat = 3

this is what PHP print_r showing = 这是PHP print_r显示的内容=

 Array
(
    ["company] => 1
    [cat] => 3
    "
)

as you can see , the cat value is only one value instea of array (1,3) 如您所见,cat值只是数组(1,3)的一个值

what i am missing here ... 我在这里想念的东西...

You can use [] to pass an array. 您可以使用[]传递数组。 Your url should become like: 您的网址应变为:

"company=1&cat[]=3&cat[]=1" “公司= 1&猫[] = 3&猫[] = 1”

Then $_GET['cat'] will return array(3,1) ; 然后$_GET['cat']将返回array(3,1) ;

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

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