• Resolved batters22

    (@batters22)


    I’m trying to use wp_ajax to call a custom function. This works perfectly with Firefox, but fails completely in eveything else (tested with Chrome, Opera and IE8).

    I’ve stripped down the code so it’s now using precisely the example code contained on the codex pages.

    I can see the request generated correctly in the console, but the response comes back as 0.

    Any ideas as to why this might be the case?

Viewing 1 replies (of 1 total)
  • Thread Starter batters22

    (@batters22)

    Ah, sheesh….

    Having read the code of admin-ajax.php, it fires a different function if the user is not logged in. I was logged in on Firefox but not on the other browsers mentioned above. Specifically, it fires:

    wp_ajax_myaction

    if you’re logged in and

    wp_ajax_nopriv_myaction

    if you’re not.

    So, all that’s required is to add a further action which included the _nopriv qualifier:

    add_action('wp_ajax_nopriv_add_foobar', 'prefix_ajax_add_foobar');

    Would be useful if this was explained in the Codex perhaps.

Viewing 1 replies (of 1 total)
  • The topic ‘wp_ajax problems in everything but Firefox’ is closed to new replies.