Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7565869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:16:05+00:00 2026-05-30T14:16:05+00:00

UPDATE 2/28/2012: This question has a solution at the end of it, thanks to

  • 0

UPDATE 2/28/2012: This question has a solution at the end of it, thanks to @charlietfl.

I have a form and an AJAX call within some JQuery script, and the AJAX appears to be executing successfully, however, the $_POST variable in the PHP file is still empty. Not sure what I’m doing wrong. My code is commented below.

The main question concerns the PHP file. Why is the PHP $_POST variable not set to ‘yes? If I do a var_dump, it consistently shows NULL. However, I believe I am manually setting ‘removeall’ to an arbitrary value, in this case ‘yes’, using the typical AJAX method. Shouldn’t the PHP file be picking up the $_POST variable with a label of ‘removeall’ as being set to ‘yes’?

I hope whatever I’m doing wrong will be completely obvious to someone.

Javascript:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<script type="text/javascript">
    $(document).ready(function(){
        $('tr.assoc_row').show();
        $('#settings-removed-msg').hide();
        $('#new-assoc-msg').hide();
        $('#formdeleteassoc').submit(function(e){
            e.preventDefault(); //This is working to prevent normal submission of the form.

            $.ajax ({
                type: 'POST',
                url: '<?php echo $cb_t2c_remove_all_url; ?>', //I have checked this to make sure it is the correct url for the PHP file.
                data: {removeall: 'yes' //This is the data that is NOT getting passed to the PHP file.
                },
                success: function() {
                    $('#settings-removed-msg').fadeIn('fast'); //This gets triggered.
                    $('tr.assoc_row').fadeOut('fast'); //This gets triggered
                    }
            });
        });
    });

PHP Code:

<?php
//remove_all.php

global $wpdb;
$prefix = $wpdb->prefix;

$remove_var_dump = $_POST['removeall']; //returning NULL
var_dump($remove_var_dump); //returning NULL

if ( $_POST['removeall'] == 'yes' ) {
    echo 'This was set to yes, everything is working.';
    }
else {
    echo 'This was not set to yes, it is still not working.';
}

?>

Solution:

/*
JQUERY action processed by AJAX
*/

add_action('init', 'cb_t2c_action_javascript');

function cb_t2c_action_javascript() {
?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" >
$(document).ready(function(){
    $('tr.assoc_row').show();
    $('#settings-removed-msg').hide();
    $('#new-assoc-msg').hide();
    $('#formdeleteassoc').submit(function(e){
        e.preventDefault(); //Works to prevent normal submission of the form.

        var data = {
            action: 'cb_t2c_ajax_action',
            removeall: 'yes'
            };

        // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php

        $.ajax ({
                type: 'POST',
                url: ajaxurl,
                data: data,
                success: function() {
                    $('#settings-removed-msg').fadeIn('fast'); //Working now
                    $('tr.assoc_row').fadeOut('fast'); //Working now
                    }
            });

        $('#formsavesettings').submit(function(){
            $('#new-assoc-msg').fadeIn('fast'); //Working now
            });
    });
});
</script>
<?php   
}
//Add the action to process the AJAX.
add_action('wp_ajax_cb_t2c_ajax_action', 'cb_t2c_action_callback');
add_action('wp_ajax_nopriv_cb_t2c_ajax_action', 'cb_t2c_action_callback');

function cb_t2c_action_callback() {
    global $wpdb; // this is how you get access to the database
    $prefix = $wpdb->prefix;

    $remove_var_dump = $_POST['removeall']; //returning NULL
    var_dump($remove_var_dump);
    $removeall = $_POST['removeall'];

    if ( isset($removeall) ){
    $wpdb->query("DELETE FROM wp_cb_tags2cats");
    }

    die(); // this is required to return a proper result
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T14:16:06+00:00Added an answer on May 30, 2026 at 2:16 pm

    try setting this:

    var data = 'removeall=yes';
    

    and setting this in your $.ajax({})

    data: data,
    

    and see if this does the trick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATE Feb 10 2012: zOompf has completed some very thorough research on this very
I have this query update user_remember_me set when='2012-07-06 05:44:27', hash='c8e9d2c0dd156b5c68d0b048e5daa948e6b8fac7' where user = '21';
I realize this question has been asked many times and I am have looked
Update (21st Sept 2016) - Thanks to Digbyswift for commenting that this solution still
Maybe this question has been anwsered, maybe not. I want to update an object
Update 18th December 2012 Since this question seems to be getting quite a few
I Have XML similar to this(omitted parts for brevity): <uformrecord> <state>Submitted</state> <created>2012-06-19T11:31:54</created> <updated>2012-06-19T11:32:13</updated> <id>53225sas3c1-d727-42cd-93a6-97cd778e5ee9</id>
Platform: ASP.NET 4.0, MVC 4 RC, VS 2012 Update: I've answer my question, myself.
UPDATE 10/19/2010 I know I asked this question a while ago, but the workarounds
I have a class that has this 2 constructors: public Conferencia(String nomeConferencia, String localizacaoConferencia,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.