AJAX Call returns 0 (4 posts)

  1. Adamski81
    Posted 3 years ago #

    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:

        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.


  2. keesiemeijer
    Posted 3 years ago #

    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.


  3. cgxsdream
    Posted 2 years ago #

    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 ;)

  4. flc
    Posted 2 years ago #

    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:

    add_action('wp_ajax_someAction', 'someCallback');

    I would like to know why, anyone?

Topic Closed

This topic has been closed to new replies.

About this Topic