Delay javascript loading of AJAX results

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Delay javascript loading of AJAX results

This topic contains 1 reply, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 3 years, 6 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #20882
    tavy87
    tavy87
    Participant

    Hi there, I have some asynchronous authentication in Javascript that takes about 2 seconds to finish, and it needs to be done BEFORE the AJAX results start rendering. I’d like to block the results from loading until then. I understand it may be hard to connect the results to a callback, but is there a simple way to add a settimeout somewhere so that the results are delayed by 2 seconds? Even if it’s inaccurate? I’m not sure where in the javascript of the plugin to even begin looking for this functionality.

    Thanks for any help!

    #20890
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    That could be possible to achieve with a small custom code snippet, I believe. So instead of enabling the auto populate feature, you can trigger the search via the javascript API whenever you need it.

    In your case you could try something like:

    add_action('wp_footer', 'asp_add_footer_action');
    function asp_add_footer_action() {
      ?>
      <script>
      jQuery(function($){
        setTimeout(function(){
          // Run the search, delayed after 2 seconds
          ASP.api(1, 'searchFor', '');
        }, 2000);
      });
      </script>
      <?php
    }

    This will add a script to the site footer to execute an empty search (basically auto-populate) manually after 2 seconds.
    I hope this helps!

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.