wp_send_json_success

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

Description

wp_send_json_success( (constant) $data = null, (null) $status_code = null ); 

Parameters (2)

0. $data — Optional. (constant) => null
Data to encode as JSON, then print and die.
1. $status_code — Optional. (null) => null
The HTTP status code to output.

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. // The HTTP status code to output. 
  8. $status_code = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wp_send_json_success($data, $status_code); 
  12.  

Defined (1)

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

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