[wp-hackers] wp_send_json_success not working with array?

J.D. Grimes jdg at codesymphony.co
Wed Jan 1 13:42:04 UTC 2014


If you var_dump( $chartData ) what do you get? I suspect that the query is failing and you will get null.

Yes, wp_send_json_success() works with arrays. It is probably used primarily with arrays.

-J.D.

On Dec 31, 2013, at 10:01 PM, BenderisGreat <greglancaster71 at gmail.com> wrote:

> 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.
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list