WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
$.ajax({
    type: "POST",
    dataType: "text",
    url: ajaxurl,
    data: {
            action: "more_news",
            nonce: nonce,
            offset: offset
    },
    success : function(data, textStatus, jqXHR){
        console.log( nonce );
        console.log( data );
        console.log( textStatus );
    }
});

Checking for this AJAX request nonce locally works perfectly. As seen below, my console prints my nonce, "Awesome", and then "success".

9a91a5fdca
Awesome
success

When on my server, my console prints my nonce TWICE (thus proving to me they're exactly the same), then success.

e2ca4eca80
e2ca4eca80
success

I'm… confused… to say the least. How is this possible? and how do I solve it?

add_action( 'wp_ajax_more_news', 'more_news' );
add_action( 'wp_ajax_nopriv_more_news', 'more_news' );

function more_news(){
    if ( !wp_verify_nonce($_POST['nonce'], 'more_news_nonce') ){
        exit($_POST['nonce']);
    }
    echo 'Awesome';
    die();
}
share|improve this question
1  
Can you show the code used to create your nonce? – vancoder Apr 3 '13 at 21:45
    
this inexplicably has started working on the server. caching issue? apache bug? I'm not sure what happened, but it's working now – zack Apr 3 '13 at 22:29

Isn't action be the same as you sent?

    data: {
        action: "more_news",
        ...

   function more_news(){
      if ( !wp_verify_nonce($_POST['nonce'], 'more_news_nonce') ){
      ....

I assume it should be

   function more_news(){
      if ( !wp_verify_nonce($_POST['nonce'], 'more_news') ){
      ....
share|improve this answer

The second parameter for wp_verify_nonce() is the action. That part is not in your question, but I guess it should be called like:

if ( !wp_verify_nonce($_POST['nonce'], $_POST['action']) ){
share|improve this answer

Your Answer

 
discard

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.