douyingmou1389 2016-03-13 19:19
浏览 6
已采纳

jquery .load将数据作为数组传递到URL并尝试在php中恢复此数组

I am trying to pass data to a server using load method like that:

$('.myform').load( "View/editEntregador.php", data, function() { });

The url I get is:

View/editEntregador.php?Array ( [id] => 67 [nome] => Augusta Ap Raym...)

So this data is been passed as an array in the URL. I can´t find a way to extract that array to an array variable in php that I can use in my page.

Any ideia?

UPDATE:

This is how the array is:

print_r($_POST);

Array
(
    [id] => 67
    [nome] => Augusta Ap Raymo Longo
    [data_inicio] => 13/03/2016
    [observacao] => 
    [numero] => Array
        (
            [0] => 4567
            [1] => 991655725
            [2] => 22222222
            [3] => 333333333
        )

    [complemento] => 
    [cep] => 14076160
    [estado] => SP
    [cidade] => Ribeirão Preto
    [bairro] => Independência
    [tipo_logradouro] => Rua
    [logradouro] =>  Brigadeiro Tobias de Aguiar
    [ddd] => Array
        (
            [0] => 16
            [1] => 16
            [2] => 16
        )

    [id_veiculo_tipo] => 1
    [placa] => bse3012
    [descricao_veiculo] => 
)

I am getting undefined index trying $_POST['id'].

  • 写回答

1条回答 默认 最新

  • dqdtgiw4736 2016-03-13 19:49
    关注

    Try this :

    var data = { id: 67, nome: 'Augusta Ap Raymo Longo'};
    $('.myform').load( "View/editEntregador.php", data, function() { });
    

    If your data is coming from $_POST then you will need to make a foreach loop to generate the data array like the example above.

    Example :

    echo 'var data={};'."
    ";
    foreach($_POST as $key => $value){
      echo "data.".$key."='".addslashes($value)."';
    ";//addslashes to escape possible slashes in your string
    }
    echo '$(\'.myform\').load( "View/editEntregador.php", data, function() { });';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突