I am trying to get an array of data from my php function using ajax but having a difficult time. Here is my php function:
function dallas_db_facebook_make_post () {
global $wpdb;
$query = "SELECT * FROM wp_dallas_facebook WHERE time > NOW() ORDER BY time LIMIT 1";
$results = $wpdb->get_results($query, ARRAY_A);
foreach($results as $result) {
$fbposttext = $result['text'];
$fbposttime = $result['time'];
$array = array('post' => $fbposttext, 'posttime' => $fbposttime);
echo json_encode($array);
}
}
Here is my jQuery function:
function send_fb_post() {
jQuery.ajax({
type: "POST",
url: my_ajax.ajaxurl,
dataType: 'json',
data: {
'action': 'dallas_db_facebook_make_post'
},
beforeSend: function() {
},
success: function(data){
var jq_json_obj = jQuery.parseJSON(data);
console.log(jq_json_obj);
},
error: function(){
},
});
};