使用$不用彷徨和$ .PARAM传递数组从jQuery来一个PHP处理程序argumento() [英] Pass array as an argumento from jQuery to a php handler using $.get and $.param()

查看:111
本文介绍了使用$不用彷徨和$ .PARAM传递数组从jQuery来一个PHP处理程序argumento()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从jQuery的一个数值数组传递给PHP文件。我用下面的一行填写此阵在我的code:

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});

然后我序列化数组中的URL使用它

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){});

但我想我的内置的URL结构如下:

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

您能帮我吗?

感谢您! :)

亚历山德拉

推荐答案

我建议你直接值添加到阵列

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},...);

有没有需要调用 $。参数直接。例如。上面的设置会产生这个查询字符串(如 Area_Array [1,2,3] ):

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的负责编码阵列正确。

jQuery takes care of encoding arrays correctly.

这篇关于使用$不用彷徨和$ .PARAM传递数组从jQuery来一个PHP处理程序argumento()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆