Title: WordPress Admin-ajax returns error 403
Last modified: October 3, 2024

---

# WordPress Admin-ajax returns error 403

 *  Resolved [mambrogi](https://wordpress.org/support/users/mambrogi/)
 * (@mambrogi)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/wordpress-admin-ajax-returns-error-403/)
 * hello folks,
 * I am using LSCache provided with my hosting provider paired with their service
   Netson Ultra Cache and WordPress Plugin.
   It works quite like a charm, if it was
   not for a blocking error with admin-ajax.php page which, once the site have been
   cached, it is no longer accessible as it responds with a Forbidden 403 error…
 * I already tried to setup exclusions like in the screenshot, and added some headers
   to the Ajax call, but nothing changed
 * [https://www.litespeedtech.com/support/forum/attachments/screenshot-2024-10-02-alle-14-15-57-png.4007/](https://www.litespeedtech.com/support/forum/attachments/screenshot-2024-10-02-alle-14-15-57-png.4007/)⌊:(⌉
 * any hint, as the website is now stuck with a load-more pagination completely 
   blocked ⌊:(⌉
 * tyvm
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fwordpress-admin-ajax-returns-error-403%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [1 year, 6 months ago](https://wordpress.org/support/topic/wordpress-admin-ajax-returns-error-403/#post-18058288)
 * no , the issue is about admin-ajax.php itself , but more like the nonce token
 * on which page you got it 403 ?
 *  Thread Starter [mambrogi](https://wordpress.org/support/users/mambrogi/)
 * (@mambrogi)
 * [1 year, 6 months ago](https://wordpress.org/support/topic/wordpress-admin-ajax-returns-error-403/#post-18058559)
 * on the main page of the atravisio.com website there is a pagination logic, which
   loads more contents upon scroll.
 * once the cache is stored though, if you start scrolling, you end up with a 403
   error on admin-ajax.php page and the paginations fails.
 * right now I have purged the cache and therefore you won’t face the error, once
   the cache will be stored, the error will rise again.
 * It’s not a nonce issue, as the code worked fine before installing LSC and everytime
   I purge the cache…
 *     ```wp-block-code
       <?phpnamespace App;use App\View\Composers\Homepage;use function Roots\view;class Ajax{    /**     * Action argument used by the nonce validating the AJAX request.     *     * @var string     */    public const NONCE = 'ajax-nonce';    /**     * Ajax constructor.     */    public static function register(): void    {        $handler = new self();        add_action('wp_ajax_load_more_articles', [$handler, 'loadMore']);        add_action('wp_ajax_nopriv_load_more_articles', [$handler, 'loadMore']);    }    public static function getNonce(): string    {        return wp_create_nonce(self::NONCE);    }    private static function checkAjaxReferer(): void    {        check_ajax_referer(self::NONCE, 'security');    }    public function loadMore(): void    {        self::checkAjaxReferer();        $page = isset($_POST['page']) ? intval($_POST['page']) : 1;        $post_id = isset($_POST['post_id']) ? intval($_POST['post_id']) : null;        $catID = isset($_POST['catID']) && $_POST['catID'] !== '' ? intval($_POST['catID']) : null;        $composer = new Homepage();        $per_page = get_option('paginazione');        $data = $composer->griglia($page, $per_page, $post_id, $catID);        if (!empty($data['items'])) {            $html = view('components.griglia-hp', ['griglia' => $data])->render();            wp_send_json_success(['html' => $html]);        } else {            wp_send_json_error('No more items');        }    }}Ajax::register();
       ```
   
 * and the JS:
 *     ```wp-block-code
       ...$.ajax({    type: 'POST',    url: wp['ajaxUrl'],    data: {      action: 'load_more_articles',      security: wp['security'],      page: currentPage + 1,      post_id: postID,      catID: catID,    },    headers: {      'X-Requested-With': 'XMLHttpRequest'  // Intestazione aggiuntiva per le richieste AJAX    },....
       ```
   
 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [1 year, 6 months ago](https://wordpress.org/support/topic/wordpress-admin-ajax-returns-error-403/#post-18060742)
 * it is nonce issue , nonce has 12 – 24 hours validity time , so it works for while
   after you purge cache , then breaks again as nonce expired
 * go to LiteSpeed Cache -> ESI -> enable ESI, add
 *     ```wp-block-code
       ajax-nonce
       ```
   
 * into ESI nonce list, save and purge all
 *  Thread Starter [mambrogi](https://wordpress.org/support/users/mambrogi/)
 * (@mambrogi)
 * [1 year, 6 months ago](https://wordpress.org/support/topic/wordpress-admin-ajax-returns-error-403/#post-18060941)
 * so something like that?
   but this should work not just for logged in users… as
   the pagination appears in home page for everyone…
 * ![](https://i0.wp.com/atravisio.com//app/uploads/2024/10/Screenshot-2024-10-08-
   alle-15.58.48.png?ssl=1)
 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [1 year, 6 months ago](https://wordpress.org/support/topic/wordpress-admin-ajax-returns-error-403/#post-18067207)
 * yes, just like that
 * login user has shorter TTL, it won’t encounter issue like nonce expiration

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘WordPress Admin-ajax returns error 403’ is closed to new replies.

 * ![](https://ps.w.org/litespeed-cache/assets/icon-256x256.png?rev=2554181)
 * [LiteSpeed Cache](https://wordpress.org/plugins/litespeed-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/litespeed-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/litespeed-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/litespeed-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/litespeed-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/litespeed-cache/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * Last activity: [1 year, 6 months ago](https://wordpress.org/support/topic/wordpress-admin-ajax-returns-error-403/#post-18067207)
 * Status: resolved