wp_send_json_success() - WordPress 函数参考中文文档

返回介绍

wp_send_json_success()

发布于 2017-09-11 字数 6110 浏览 1039 评论 0

wp_send_json_success( mixed $data = null,  int $status_code = null )

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


描述


参数

$data

(mixed)
(Optional)
Data to encode as JSON, then print and die.

Default value: null

$status_code

(int)
(Optional)
The HTTP status code to output.

Default value: null


源代码

File: wp-includes/functions.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 );
}

更新日志

Version 描述
4.7.0 The $status_code parameter was added.
3.5.0 Introduced.

相关函数

Uses

  • wp-includes/functions.php:
    wp_send_json()

Used By

  • wp-admin/includes/ajax-actions.php:
    wp_ajax_get_community_events()
  • wp-includes/class-wp-customize-nav-menus.php:
    WP_Customize_Nav_Menus::ajax_insert_auto_draft_post()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_search_install_plugins()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_delete_plugin()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_search_plugins()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_install_theme()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_update_theme()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_delete_theme()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_install_plugin()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_get_post_thumbnail_html()
  • wp-includes/customize/class-wp-customize-selective-refresh.php:
    WP_Customize_Selective_Refresh::handle_render_partials_request()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_generate_password()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_save_wporg_username()
  • wp-includes/class-wp-customize-nav-menus.php:
    WP_Customize_Nav_Menus::ajax_load_available_items()
  • wp-includes/class-wp-customize-nav-menus.php:
    WP_Customize_Nav_Menus::ajax_search_available_items()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_crop_image()
  • wp-includes/class-wp-customize-manager.php:
    WP_Customize_Manager::refresh_nonces()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_update_plugin()
  • wp-admin/includes/class-wp-press-this.php:
    WP_Press_This::add_category()
  • wp-admin/includes/class-wp-press-this.php:
    WP_Press_This::save_post()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_destroy_sessions()
  • wp-admin/custom-background.php:
    Custom_Background::ajax_background_add()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_parse_embed()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_parse_media_shortcode()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_set_attachment_thumbnail()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_save_attachment_order()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_send_attachment_to_editor()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_send_link_to_editor()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_get_revision_diffs()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_save_user_color_scheme()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_query_themes()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_set_post_thumbnail()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_wp_fullscreen_save_post()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_get_attachment()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_query_attachments()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_save_attachment()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_save_attachment_compat()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_find_posts()
  • wp-admin/custom-header.php:
    Custom_Image_Header::ajax_header_crop()
  • wp-admin/custom-header.php:
    Custom_Image_Header::ajax_header_add()
  • wp-admin/custom-header.php:
    Custom_Image_Header::ajax_header_remove()
  • wp-includes/class-wp-customize-manager.php:
    WP_Customize_Manager::save()
  • wp-includes/class-wp-customize-widgets.php:
    WP_Customize_Widgets::wp_ajax_update_widget()
  • Show 38 more used by
    Hide more used by


User Contributed Notes

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Basic Example

    
    jQuery( document ).ready( function() {
    
    	jQuery( '#btn_save' ).click( function( e ) {
    		e.preventDefault();
    		jQuery.post( pluginUrl+ 'ajax/save_field.php', 
    			jQuery( '#my-form' ).serialize(), function( data ) {                        
    				alert( data.message ); 
    			}
    		);
    	} );
    } );
    

    save_field.php:

    
    // Bootstrap WP
    
    $return = array(
    	'message' => __( 'Saved', 'textdomain' ),
    	'ID'      => 1
    );
    wp_send_json_success( $return );
    

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!