I'm getting this error in php:
Invalid argument supplied for foreach()
I am tring to create an array in jquery for the input values
<input type="text" class="passenger">
<input type="text" class="passenger">
<input type="text" class="passenger">
Then the js is :
var passengers = new Array();
$('.passenger').each(function(){
if($(this).val() == " "){
passengers.push(JSON.stringify($(this).val()));
}
});
Then after i post it to php, i am wanting it so i displays all the passengers
at the moment, this is not working. Why not
foreach($passengers as $pass){
$each_passengers = json_decode($pass);
}
$passengersis not a array but a string. You are doing a.stringifywhich convert the json data to a string.passengers.push($(this).val());andvar data = JSON.stringify(passengers)before data sending and then something like$passengers = json_decode($data)in PHP.if($(this).val() == " "){will just add empty values