0

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'].

2
  • Could you post how your data array is created? Commented Mar 13, 2016 at 19:27
  • Possible duplicate of jquery build http query string Commented Mar 13, 2016 at 19:35

1 Answer 1

1

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={};'."\n";
foreach($_POST as $key => $value){
  echo "data.".$key."='".addslashes($value)."';\n";//addslashes to escape possible slashes in your string
}
echo '$(\'.myform\').load( "View/editEntregador.php", data, function() { });';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.