WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a feature in my current project that will be allow multiple ajax requests - I've got a single nonce request worked out (via this tute), but am somewhat unsure how to figure in multiple nonce requests.

functions.php: localize, create a single nonce

           'ajaxurl'        => admin_url( 'admin-ajax.php' ),
           'requestNonce'   => wp_create_nonce('b99-request-nonce') 

calling js:

        type    : 'POST',
        url     : B99ajax.ajaxurl,
        data    : {
            action          : 'b99-ajax-submit',
            requestNonce    : B99ajax.requestNonce

receiving php

public function b99_ajax_submit() {
        $nonce = $_POST['requestNonce'];
        if ( ! wp_verify_nonce( $nonce, 'b99-request-nonce' ) )

... sql, response

At this point, I can reuse this nonce repeatedly, but I think that defeats the purpose of the nonce check. My solution will be to request a new nonce in the receiving php, assign B99ajax js object that variable, and send it back to the requesting page for the "next" ajax sequence.

Is there a better way?

share|improve this question
up vote 2 down vote accepted

That is basically the way WordPress does it and pretty much the only way to do it, simply have your receiving PHP function create a new nonce add send it back with your response, then just update the value on your JS before the next round.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.