receiving data from server with ajax call
-
as posted in the hacks forum, but no answer – i posted the question here in the hope someone knows how to do it.
i have a jvascript function:
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); } ); }; }
and my php function which is called via ajax:
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 the main php file i have defined:
action( 'wp_ajax_bbnuke_players_page', 'bbnuke_show_players_page'); add_action( 'wp_ajax_nopriv_bbnuke_players_page', 'bbnuke_show_players_page');
I would like to receive from the ajax call the post id i have created and/or the post_content to show in a new window to the user.
how i can send data back? i only get a “success: true” message back.
- The topic ‘receiving data from server with ajax call’ is closed to new replies.