Reputation: 101
Basic question, complex headache. Trying to build a phonegap app, I have a section where a user inputs multiple emails to register, together with a title.
<input type="text" name="person[]">
Then, Ajax takes care of that,
$.ajax({
type: "POST",
//url: "php/insert_teams.php",
url: ip + "php/insert_teams.php",
data: datastring,
cache: false,
});
Notice I have a comment on the first url which is what I used when working locally and everything was ok. Now, I uploaded the file to a domain and the datastring ( which is sent correctly as it was with the local PHP) is not treated correctly by the PHP file.
<?php
$person=$_POST['person'];
var_dump($person);
?>
This is what I get through Chrome's developer tools > network > Headers > Form Data when I call the url:
name:qwe
person[]:[email protected]
person[]:[email protected]
person[]:bla
which seems ok to me. Then this is what I get in response:
string(3) "bla"
For some reason, when using the external php it only returns me the last element of the array, always. Am I doing something wrong? Forgetting some detail?
Thanks for reading.
Upvotes: 1
Views: 120
Reputation: 101
Thanks for the answers, the datastring was already a Serialize. It seems that when using external php, chrome's ripple emulator doesn't do the job, and only works through the use of phonegap developer app on your phone.
I'm unable to delete the question now, so hopefully this could help somebody else.
Upvotes: 0
Reputation: 1473
Use jquery serialize to send array inputs:
var myInputValues = $('#yourInput').serialize();
$.ajax({
type: "POST",
//url: "php/insert_teams.php",
url: ip + "php/insert_teams.php",
data: {'key' : myInputValues),
cache: false,
});
Upvotes: 1