Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#15266 closed defect (bug) (invalid)

receiving data from server with ajax call

Reported by: christian_gnoth Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0.1
Component: General Keywords: ajax
Focuses: Cc:


i am using an ajax call in my plugin to create a new page with wp_insert_post and I would like to show this new post to the front-end user.

my javascript function is this:

function show_players_page(id)
    var data = {
             action: 'bbnuke_players_page',
             bbnuke_player_id: id

    // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
    jQuery.post( ajaxurl, data,
       function( response )

my php function which is called is:

function  bbnuke_show_players_page()
  global $wpdb;

  $player_id = $_POST['bbnuke_player_id'];

  $user_id = get_current_user_id();
  if (!$user_id)
    $user_id = 1;

  //  create the page content
  $bbnuke_post_content =  bbnuke_widget_playerstats( $player_id, false );

  $bbnuke_post = array(
    'menu_order'     => 0,
    'comment_status' => 'closed',
    'ping_status'    => 'closed',
    'post_author'    => $user_id,
    'post_content'   => $bbnuke_post_content,
    'post_name'      => 'baseballnuke-players-page',
    'post_status'    => 'publish',
    'post_title'     => 'baseballNuke - Players Page' . $player_id,
    'post_type'      => 'page'

  $post_id = wp_insert_post( $bbnuke_post );


  $url = get_bloginfo('url') . '/?p=' . $post_id;

  bbnuke_update_option( 'bbnuke_ajax_post_url' , $url );


in my plugin file is this:

add_action( 'wp_ajax_bbnuke_players_page', 'bbnuke_show_players_page'); add_action( 'wp_ajax_nopriv_bbnuke_players_page', 'bbnuke_show_players_page');

how I can send the create post_id back to the calling javascript function?

the response only contains "success: true".

how i can set the responsetext or receive data from the server?

there is now description in the worpress docs how to receive data with the response.

Change History (1)

#1 @scribu
8 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

trac is for reporting bugs in WordPress core.

You can ask your question in any these places:

Note: See TracTickets for help on using tickets.