dongxifu5009
dongxifu5009
2013-09-29 11:41

使用AJAX将数组和字符串从Javascript传递到PHP

  • php
  • ajax
  • javascript
  • jquery

I have the following ajax call.

My addList variable holds a string: list=Sports&list=Cars&list=Outdoor&new_list=123123

I want to grab the addList in my PHP file as

$_POST['list'] is an array with values Sports, Cars, Outdoor
$_POST['new_list'] is a string 123123

But I couldnt convert the POST string into right forms.

I can create arrays/loops in both sides but it didnt feel right.

Whats the convenient way of doing it?

jQuery.ajax({  
                    type: "post",  
                    url: ajax_var.url,  
                    data: "action=post-list&nonce="+ajax_var.nonce+"&post_list=&post_id="+post_id+"&" + addList,  
                    success: function(count){  
                        alert("done"); 
                    }  
                }); 

Any help will be appreciated. thanks!

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答