mardi 24 mars 2015

create array from php sql querry and pass it to ajax


I'm trying to get my results from a sql query into an array in javascript. I'm trying the following:


php:



$query = mysqli_query($connection, "select a, b, c from table");

$result_a = array();
$result_b = array();
$result_c = array();
while($row = mysqli_fetch_array($query)) {
$result_a[] = $row['a'];
$result_b[] = $row['b'];
$result_c[] = $row['c'];
}
echo json_encode(array('a'=>$result_a,'b'=>$result_b, 'c'=>$result_c ));


javascript:



$.ajax({
type: "POST",
url: "http://ift.tt/1ss5ALA",
data: dataString3,
cache: false,
error: function(){},
success: function(data){
alert (data.a);
alert (data.b);
alert (data.c);
},
});
return false;


The php arrays have the data I'm looking for but the alerts in javascript are undefined. Any help would be appreciated.





Aucun commentaire:

Enregistrer un commentaire