• Hi All,

    I am having a problem with an AJAX call I have implemented on my WordPress website.

    The AJAX request is calling a function in the wp-admin:

    $.ajax({
        type: "POST",
        url: "/wp-admin/admin-ajax.php",
        data: 'subscribe_action&'+str
    });

    The subscribe_action function uses ‘curl’ to get data from an other website.

    When I look in firebug I see that the function is returning 0 almost all the time.
    It took me a while but I discovered that it works when I login to wordpress admin in an other browser tab.

    I have the impression that it has something to do with sessions and authentication.

    The subscribe_action already has die(); implemented at the end.
    I don’t think it has something todo with the curl implementation as it is working perfectly when I am also logged in as admin.

    I hope somebody can help me.

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    If an AJAX request succeeds, it will return a 0.

    To make it work on the front end of your site you have to use the wp_ajax_nopriv_my_action.

    http://codex.wordpress.org/AJAX_in_Plugins#Ajax_on_the_Viewer-Facing_Side

    if you are doing this for front-end facing then logout from your wp admin panel first, cause when you are logged in to admin it creates an admin type session, and if issue still persist then try to debug your code.

    Try it 😉
    Thanks

    If you put your

    add_action(‘wp_ajax_someAction’, ‘someCallback’);

    inside a function or if block (and I guess any block) it wont work. For example this wont work:

    if(…):
    add_action(‘wp_ajax_someAction’, ‘someCallback’);
    endif;

    I would like to know why, anyone?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘AJAX Call returns 0’ is closed to new replies.