duande1986 2014-02-27 17:49
浏览 33
已采纳

jQuery从datatables序列化到没有ajax的PHP数组

I have a table using Datatables. I have a setup pretty much like this link in the fact that I have form fields in the table and that they are submitted. I don't want to use ajax, I want to use the submit button.

This is part of my code:

$('#form').submit( function() {
    var sData = $('input', oTable.fnGetNodes()).serialize ();

    console.log(sData);
    $('#form-values').val(sData);

} );

So I'm taking the serialized data and I'm putting it in a hidden input box with the id #form-values. Once I submit, In the server side I can get the serialized data with $_POST['form-values'] but of course... the data is serialized... I would want that data in an array so I can analyze it and insert some of them in a database.

I tried doing unserialize($_POST['form-values']) but it gives me the error Notice: unserialize(): Error at offset 0 of 1098 bytes in...

My serialized data looks like:

comments%5B56%5D=&comments%5B35%5D=&comments%5B12%5D=&comments%5B32%5D=

But I would want it to be:

Array ( [comments] => Array ( [56] => [35] => [12] => [32] => 
  • 写回答

3条回答 默认 最新

  • dsvtnz6350 2014-02-27 17:55
    关注

    You can get just the atributes from a URL using parse_url()

    Once you have that you can use parse_str() to convert them to variables, it works with multidimensional arrays too!

        $str = "first=value&arr[]=foo+bar&arr[]=baz";
    
        parse_str($str, $output);
        echo $output['first'];  // value
        echo $output['arr'][0]; // foo bar
        echo $output['arr'][1]; // baz
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 MATLAB yalmip 可转移负荷的简单建模出错,如何解决?
  • ¥15 数学的三元一次方程求解
  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?