[resolved] wp_ajax problems in everything but Firefox (2 posts)

  1. batters22
    Posted 3 years ago #

    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?

  2. batters22
    Posted 3 years ago #

    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:


    if you're logged in and


    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.

Topic Closed

This topic has been closed to new replies.

About this Topic