duanmu6752 2011-08-11 00:20 采纳率: 0%
浏览 103
已采纳

使用$ .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

$.param(Area_Array);

I can see that the array is built correctly using:

alert(decodeURIComponent($.param(Area_Array)));

which returns, for instance, the following:

A[]=0&A[]=1&A[]=2

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:

http://somehost/some.php?b1=0&b2=5&b3=20&b4=1&A[]=0&A[]=1&A[]=2

Could you please help me?

Thank you!!! :)

Alexandra

  • 写回答

1条回答 默认 最新

  • doudong2149 2011-08-11 00:29
    关注

    I suggest that you directly add the values to the array

    Area_Array.push(ui.value);
    

    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]):

    b1=0&b2=5&b3=20&b4=1&A[]=1&A[]=2&A[]=3
    

    jQuery takes care of encoding arrays correctly.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘