wp_send_json_success

函式
wp_send_json_success ( $data = null, $status_code = null, $options = 0 )
引數
  • (mixed) $data Optional. Data to encode as JSON, then print and die. Default null.
    Required:
    Default: null
  • (int) $status_code Optional. The HTTP status code to output. Default null.
    Required:
    Default: null
  • (int) $options Optional. Options to be passed to json_encode(). Default 0.
    Required:
定義位置
相關方法
wp_send_jsonwp_send_json_errorwp_is_json_requestwp_is_jsonp_requestwp_preload_resources
引入
3.5.0
棄用
-

wp_send_json_success: 這是一個WordPress的函式,用來向客戶端傳送一個表示成功的JSON響應。它允許你向客戶端提供一個成功資訊和可選的資料,這些資料可以用來在客戶端處理成功。

向Ajax請求傳送一個JSON響應,表示成功。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_send_json_success( $data = null, $status_code = null, $options = 0 ) {
$response = array( 'success' => true );
if ( isset( $data ) ) {
$response['data'] = $data;
}
wp_send_json( $response, $status_code, $options );
}
function wp_send_json_success( $data = null, $status_code = null, $options = 0 ) { $response = array( 'success' => true ); if ( isset( $data ) ) { $response['data'] = $data; } wp_send_json( $response, $status_code, $options ); }
function wp_send_json_success( $data = null, $status_code = null, $options = 0 ) {
	$response = array( 'success' => true );

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

	wp_send_json( $response, $status_code, $options );
}

常見問題

FAQs
檢視更多 >