[wp-hackers] wp_send_json_success not working with array?
BenderisGreat
greglancaster71 at gmail.com
Wed Jan 1 03:01:19 UTC 2014
Here is my code - The goal is to return the database data formatted to update
a JS chart. For some reason the function isnt even seeing the $chartData as
executing. if ($chartData) returns false.
function ams_chart_range_selection() {
global $wpdb, $_current_member;
$range = $_POST['range'];
$limit = 5;
if ($range == 'week' )
$limit = 7;
elseif ($range == 'month') {
$limit = 30;
} else
$limit = 90;
$logDataTable = $wpdb->prefix . 'jo_plugin_options';
$chartData = $wpdb->get_results( $wpdb->prepare("SELECT * FROM
$logDataTable WHERE user_id = %d ORDER BY date ASC LIMIT %d",
$_current_member->ID, $limit), ARRAY_A );
$max = count($chartData);
$converted = array();
$counter = 0;
foreach ($chartData as $item) {
$converted[] = "[".$counter++.",".$item['date']."]";
$list = implode(",",$converted);
}
if (!$chartData) {
wp_send_json_error();
} else {
$data = array(
'range' => $range,
'list' => $list );
wp_send_json_success($data);
}
}
--
View this message in context: http://wordpress-hackers.1065353.n5.nabble.com/wp-send-json-success-not-working-with-array-tp43098.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
More information about the wp-hackers
mailing list