Title: Intermittent ajax issues using plugin
Last modified: April 24, 2023

---

# Intermittent ajax issues using plugin

 *  Resolved [the_lar](https://wordpress.org/support/users/the_lar/)
 * (@the_lar)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/intermittent-ajax-issues-using-plugin/)
 * Hi all,
 * I’ve recently activated Litespeed on our site and benefitted greatly from a boost
   in overall site speed and performance, this has been great for our pagespeed 
   metrics.
 * I am now and then having users report issues with our ajax features on the site,
   such as our tyre search widget which features on our homepage and various others.
   Basically selecting a Tyre Width or a Tyre Profile always populates and activates
   the next drop down, but Litespeed is causing 503 errors to be returned from admin-
   ajax.php.
 * I know for sure that this is the cause because as soon as I go to Litespeed and
   select ‘Purge All’ – it starts working again.
 * This issue is NOT present for all users, but for certain it is affecting some
   of sales guys and a handful of customers.
 * Just to note, my ajax requests are sent with the parameter `ajax_nonce` and in
   the past I have tried to fix this by adding the following to ESI nonces in section
   5 of the settings:
   —–stats_noncesubscribe_nonceajax_noncenonce*_nonce—–but this
   hasn’t seemed to help at all.
 * Is there any way to simply disable Litespeed on all admin-ajax.php requests?
 * Thanks in advance
 * Kevin
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fintermittent-ajax-issues-using-plugin%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/intermittent-ajax-issues-using-plugin/#post-16683524)
 * please search through the ajax call script , find out the part about “ajax_nonce”
   you will need to find the nonce name
 *  Thread Starter [the_lar](https://wordpress.org/support/users/the_lar/)
 * (@the_lar)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/intermittent-ajax-issues-using-plugin/#post-16684258)
 * Hi there,
 * I found this in the documentation – [https://docs.litespeedtech.com/lscache/lscwp/api/#convert-custom-nonce-to-esi](https://docs.litespeedtech.com/lscache/lscwp/api/#convert-custom-nonce-to-esi)–
   so I’ve now added `do_action('litespeed_nonce', 'my_nonce_name');` just above
   where I call `wp_create_nonce()` as it says.
 * Is that all I need to do or is there more to it? I only did this late last night,
   but I have had no more reports of the issue since.
 * Thanks
 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/intermittent-ajax-issues-using-plugin/#post-16686984)
 * yes , or you can add the `my_nonce_name` to the ESI nonce list , but this requires
   your server supports ESI
 *  Thread Starter [the_lar](https://wordpress.org/support/users/the_lar/)
 * (@the_lar)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/intermittent-ajax-issues-using-plugin/#post-16688130)
 * Perfect, thank you! As I say, haven’t had any re-occurance since I put this in
   place 2 days ago… fingers crossed!
 *  Thread Starter [the_lar](https://wordpress.org/support/users/the_lar/)
 * (@the_lar)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/intermittent-ajax-issues-using-plugin/#post-16691719)
 * Hi again,
 * Just picking this up again as I have had a re-occurrance of the issue and I managed
   to get the user to give me some screenshots which I’d like to share.
 * Firstly, just a bit of background on my setup – our site is based on roots/sage
   theme 9.0.9. In my setup.php file I have the following code snippet:
 *     ```wp-block-code
       /**
        * Theme assets
        */
       add_action('wp_enqueue_scripts', function () {
           wp_enqueue_style('sage/main.css', asset_path('styles/main.css'), false, null);
           wp_enqueue_script('sage/main.js', asset_path('scripts/main.js'), ['jquery'], null, false);
   
           // Litespeed
           do_action('litespeed_nonce', '<my_nonce_name>');
   
           $ajax_params = array(
               'ajax_url' => admin_url('admin-ajax.php'),
               'ajax_nonce' => wp_create_nonce('<my_nonce_name>'),
               'asset_path' => asset_path(''),
           );
           wp_localize_script('sage/main.js', 'ajax_object', $ajax_params);
           ...
       }
       ```
   
 * Obviously I’ve changed my actual nonce name to <my_nonce_name> in the code above.
 * As you can see, I’m calling `litespeed_nonce` before calling `wp_create_nonce()`
   as instructed here – [https://docs.litespeedtech.com/lscache/lscwp/api/#convert-custom-nonce-to-esi](https://docs.litespeedtech.com/lscache/lscwp/api/#convert-custom-nonce-to-esi)
 * My Javascript code where the ajax call is made is:
 *     ```wp-block-code
       $button.bind('click', function(){
           console.log('size search button click');
           $button.addClass('loading');
           let data = {
               action: 'postcode_check',
               // eslint-disable-next-line no-undef
               nonce: ajax_object.ajax_nonce,
               postcode: $tyre_postcode.val(),
           }
           $.ajax({
               // eslint-disable-next-line no-undef
               url: ajax_object.ajax_url,
               type: 'POST',
               data: data,
               dataType: 'json',
               success: function (response) {
                   ...
               }
           });
       }
       ```
   
 * As you can see I’m accessing the ajax_object that was registered when localizing
   the script in setup.
 * Finally, my PHP script for postcode_check has `check_ajax_referer` as the first
   line of the function and looks like this:
 *     ```wp-block-code
       add_action('wp_ajax_nopriv_postcode_check', [$this, 'postcode_check']);
       add_action('wp_ajax_postcode_check', [$this, 'postcode_check']);
   
       public function postcode_check()
       {
           check_ajax_referer('<my_nonce_name>', 'nonce');
           ...
       }
       ```
   
 * The part of the site where the issue occured for this particular user is on our
   homepage, interacting with the Tyre Search widget which is at the top of the 
   page:
 * ![](https://uploadpie.com/LWuy9w)
 * When the user selects a tyre width, tyre profile and tyre size, then enters their
   postcode – clicking ‘See Products’ performs an ajax request to the above `postcode_check`
   function. It is this ajax request that is failing for the user.
 * I have managed to capture the following screenshots of the request in Firefox
   web console from their laptop.
 * Request headers:
 * ![](https://uploadpie.com/XfjAOl)
 * ![](https://uploadpie.com/EsYEb8)
 * Request:
 * ![](https://uploadpie.com/Tq6ZS1)
 * Response:
 * ![](https://uploadpie.com/eFgk3J)
 * As you can see, the request to `postcode_check` is giving me a 403 error.
 * Notably when I tried just clearing the Litespeed cache alone, the users error
   persisted. It wasn’t until I commented out the `check_ajax_referer` code in the
   PHP function that I was able to clear the users error.
 * Hope that the details above will enable me to get an idea of what is causing 
   these intermittent issues.
 * Many thanks
 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/intermittent-ajax-issues-using-plugin/#post-16693980)
 * please provide the report number , you can get it in toolbox -> report -> click“
   send to LiteSpeed”
 *  Thread Starter [the_lar](https://wordpress.org/support/users/the_lar/)
 * (@the_lar)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/intermittent-ajax-issues-using-plugin/#post-16694961)
 * Hi there, report number is **LCFHTFTM**
 * Kevin
 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/intermittent-ajax-issues-using-plugin/#post-16697043)
 * hmmmm? is that nonce name in ESI nonce list the one you use ?
 * for instance I don’t see any issue
 * please try enable debug log with include URI as `lsesi` , this is subrequest 
   from ESI that will send to plugin , it should come with 30 minutes of TTL , please
   enable log and see what actually occurs
 *  Thread Starter [the_lar](https://wordpress.org/support/users/the_lar/)
 * (@the_lar)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/intermittent-ajax-issues-using-plugin/#post-16703130)
 * Hi there,
 * Do you mean the one that starts with ‘4×4’ which is 3rd in the list?
 * That’s the same one from where I am doing this in my code:
 *     ```wp-block-code
       do_action('litespeed_nonce', '<my_nonce_name>');
       ```
   
 * but I’ve removed the actual name and replaced it with `<my_nonce_name>` – I wasn’t
   sure if it needed to be in the ESI nonces list so that is why I put it in there.
 * Could you explain the process of enabling the debug log using `lsesi` to me please–
   is it something I add to the URL? And where do I see the log once it has been
   activated?
 * Many thanks
 * Kevin
 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/intermittent-ajax-issues-using-plugin/#post-16708815)
 * please go to toolbox -> debug setting -> set debug IP to ALL , log level to advance,
   debug include URI , add `lsesi` into the field
 *  Thread Starter [the_lar](https://wordpress.org/support/users/the_lar/)
 * (@the_lar)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/intermittent-ajax-issues-using-plugin/#post-16711332)
 * OK I will do that now.
 * I may have had a bit of breakthrough – I have just triggered the error myself
   and captured this screenshot of the Firefox console which gives some additional
   information:
 * ![](https://uploadpie.com/w8A5Xj)
 * Does this help?
 *  Thread Starter [the_lar](https://wordpress.org/support/users/the_lar/)
 * (@the_lar)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/intermittent-ajax-issues-using-plugin/#post-16711355)
 * Hi, on the debug settings, I have set it up like this:
 * ![](https://uploadpie.com/lRlEW4)
 * But as you can see it’s saying Invalid IP when I add ALL to the field – but maybe
   that’s not what you meant?? Also, should `lsesi` be in the Debug URI includes
   field like that?
 *  Thread Starter [the_lar](https://wordpress.org/support/users/the_lar/)
 * (@the_lar)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/intermittent-ajax-issues-using-plugin/#post-16713091)
 * Ugh… images expired in previous messages, here is the firefox console again –
 * ![](https://i0.wp.com/i.ibb.co/T06YMvN/Screenshot-2023-05-04-at-16-48-40.png?
   ssl=1)
 * And here is the Litespeed debug config as I’ve set it up –
 * ![](https://i0.wp.com/i.ibb.co/BNtNtZH/Screenshot-2023-05-04-at-17-00-19.png?
   resize=537%2C454&ssl=1)
 * Hope these help

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

The topic ‘Intermittent ajax issues using plugin’ 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/)

 * 13 replies
 * 2 participants
 * Last reply from: [the_lar](https://wordpress.org/support/users/the_lar/)
 * Last activity: [3 years, 1 month ago](https://wordpress.org/support/topic/intermittent-ajax-issues-using-plugin/#post-16713091)
 * Status: resolved