duan20145 2011-07-28 07:15
浏览 224

jQuery序列化数组

I have a webpage with the following input:

<input type='text' name='packagedims[]' value='1' id='packagedims' title='Package1' />

I'm using it in jQuery as so:

var packagedims = $('input#packagedims').serialize();

and then I'm using jQuery.ajax to post it to my php file:

'&packagedims=' + packagedims

(I know I could use Serialize() on the whole form but I'm modifying existing code so haven't got round to doing that yet. In the above line I'm sending individual variables to php.)

When I test the output using alert() I get the following:

&packagedims=packagedims%5B%5D=1&packagedims%5B%5D=2

I just wanted to check that this sort of output is correct and that using unSerialize() in my php file will be able to split this into a proper array.

Thank you,

  • 写回答

1条回答 默认 最新

  • duankuangxie9070 2011-07-28 07:19
    关注

    .serialize() [docs] already returns a string in the form of

    key=value&key=value&...
    

    Don't append to something else, otherwise it becomes

    key=key=value&...
    

    which is incorrect. So do not concatenate it with '&packagedims='.

    There is no need to use any unserialize function in PHP. The data will be sent as GET or POST data and be available in PHP through $_GET or $_POST. E.g. if you make a POST request, $_POST['packagedims'] will be an array containing the values.

    Variables From External Sources might be worth a read.

    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大