﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	severity	resolution	keywords	cc
15266	receiving data from server with ajax call	christian_gnoth		"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)
{
  jQuery()
  {
    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 )
       {
         alert(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 );

  sleep(3);

  $url = get_bloginfo('url') . '/?p=' . $post_id;

  bbnuke_update_option( 'bbnuke_ajax_post_url' , $url );

  exit;
}
}}}


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."	defect (bug)	closed	normal		General	3.0.1	normal	invalid	ajax	
