WordPress at a glance

wp_send_json_success() WP 1.0

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

Notes:

  • Since 4.7.0 The $status_code parameter was added.
Works based on: wp_send_json()

No Hooks.

Return

Nothing (null).

Usage

wp_send_json_success( $data, $status_code );
$data(mixed)
Data to encode as JSON, then print and die.
Default: null
$status_code(int)
The HTTP status code to output.
Default: null

Code of wp_send_json_success: wp-includes/functions.php VER 4.9.8

<?php
function wp_send_json_success( $data = null, $status_code = null ) {
	$response = array( 'success' => true );

	if ( isset( $data ) )
		$response['data'] = $data;

	wp_send_json( $response, $status_code );
}

Related Functions

From tag: AJAX

More from category: Helper Functions

No comments
    Hello, !     Log In . Register