first file:
$data = array();
if ($result->num_rows > 0) {
while( $row = $result->fetch_assoc()) {
$data[] = $row["input"]; // make sure that db table column name is `input`
}
echo json_encode($data);
second file:
function retrieveData(){
$.post('quick.php',{}, function(data){
var new_data = $.parseJSON(data); // decode json data and covert it to jquery array
$.each(new_data, function(index, element) { // iterate over array
window.alert(element); // alert each element of the array
});
});
}
I am trying to send the data I get from the database to another PHP file as an array but it is not working. Can anyone please help me with that?
you make and ajax request but i don't see the success and the error section you should try this
$.ajax({
url: 'quick.php',
type: 'POST',
data: {},
success: function (data)
{
var new_data = $.parseJSON(data); // decode json data and covert it to jquery array
$.each(new_data, function(index, element) { // iterate over array
window.alert(element); // alert each element of the array
});
},
error: function(json){
//Manage the error here
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.