0

I know this has come up a number of times but it is driving me nuts. I've spend hours trying to debug it.

My AJAX isn't working for non-logged in users.

Here's me action:

add_action('wp_ajax_nopriv_ah_update', array($tracker, 'update_tracking'), "1");
add_action('wp_ajax_ah_update', array($tracker, 'update_tracking'), "1");

I've placed them inbetween is_admin and out of it. I've taken the server side code out of the class and put it in its own function. But nothing works.

I should state that it works fine for all logged-in users

I've done a var_dump() on $_GET['request'] and it all looked fine.

if ( !empty( $_REQUEST['action'] ) )
    do_action( 'wp_ajax_nopriv_' . $_REQUEST['action'] );

die('-1');

If I change the admin-ajax.php code to this it works fine:

if ( !empty( $_REQUEST['action'] ) ) {

    do_action( 'wp_ajax_nopriv_' . $_REQUEST['action'] );

} else {

    die('-1');

}

I'm a total loss as to what is causing this to happen.

Perhaps there is something else in the script that is blocking no-logged in user access, but I can't see it.

2
  • Just a guess: Did you change the line endings? Maybe during the transfer of this file to the server?
    – fuxia
    Commented Jun 11, 2012 at 13:47
  • 1
    Does your actual AJAX callback end with a call to die()? If your code doesn't, then WordPress will fire the action hook as expected and still call die('-1') afterwards.
    – EAMann
    Commented Jun 11, 2012 at 13:57

1 Answer 1

5

You should end all "async" functions with die() or exit, otherwise WordPress does it for you returning -1.

1
  • At the bottom of the callback I had return *database query". So I removed the return from the beginning of the database query and put die() at the end and it works fine now. Thanks for all your responses.
    – AndyW
    Commented Jun 11, 2012 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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