2011-08-11 00:20
浏览 97

使用$ .get和$ .param()将数组作为参数从jQuery传递给php处理程序

I need to pass an array of numeric values from jQuery to a php file. I fill this array in my code using the following line:

Area_Array.push({name: 'A[]', value: ui.value});

Then I serialize the array to use it in an URL


I can see that the array is built correctly using:


which returns, for instance, the following:


that is fine for me, but I don't know now how to insert it inside my $.get which is also sending another parameters:

$.get("some.php", { b1 : 0, b2 : 5, b3: 20, b4 : 1},function(foo){});

But I want my built URL to have the following structure:


Could you please help me?

Thank you!!! :)


  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doudong2149 2011-08-11 00:29

    I suggest that you directly add the values to the array


    and then set it as parameter:

    $.get("some.php", {b1: 0, b2: 5, b3: 20, b4: 1, A: Area_Array},...);

    There is no need to call $.param directly. E.g. the setup above would generate this query string (if Area_Array was [1, 2, 3]):


    jQuery takes care of encoding arrays correctly.

    打赏 评论

相关推荐 更多相似问题