wp_send_json_success

Send a JSON response back to an Ajax request, indicating success.

Description

wp_send_json_success( (null) $data = null ); 

Parameters (1)

0. $data — Optional. (null) => null
Data to encode as JSON, then print and die.

Usage

  1. if ( !function_exists( 'wp_send_json_success' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4. // Data to encode as JSON, then print and die. 
  5. $data = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_send_json_success($data); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/functions.php  
  1. function wp_send_json_success( $data = null ) { 
  2. $response = array( 'success' => true ); 
  3.  
  4. if ( isset( $data ) ) 
  5. $response['data'] = $data; 
  6.  
  7. wp_send_json( $response );