简体   繁体   中英

Ajax requests in Wordpress, can't get my custom function to execute

I am making ajax requests in wordpress to admin-ajax.php file using jQuery:

function ajaxSubmit() {
    var FormData = jQuery(this).serialize();    
    jQuery.ajax({
        type: "POST",
        url: "/wp-admin/admin-ajax.php",
        data: FormData, 
        success: function(data) {
            console.log(data);
        }
    });
    return false;
}
$('#form').submit(ajaxSubmit);

here is the code from functions.php file:

function activitysubmitTeamMeetingPt(){
    die(var_dump($_POST, $_GET));
}
add_action( 'wp_ajax_activitysubmitTeamMeetingPt', 'activitysubmitTeamMeetingPt' );
add_action( 'wp_ajax_nopriv_activitysubmitTeamMeetingPt', 'activitysubmitTeamMeetingPt' );

Also, in the form I do have a hidden attribute for action

<input type="hidden" name="action" value="submitTeamMeetingPt" /> 

As per the code, all form data would be printed on the screen but that doesn't happen. And I have verifed from firebug that Xhr request to admin-ajax.php is being fired but for some reason activitysubmitTeamMeetingPt() doesn't get called/executed and ajax request just returns 0 with http statuscode 200.

Now,I am wondering was why activitysubmitTeamMeetingPt() is not being executed?

Update, I figured it out. hidden attribute for action should be:

<input type="hidden" name="action" value="activitysubmitTeamMeetingPt" /> 

now it works just fine. thanks for looking everyone

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM