• Resolved Si

    (@shopods)


    Nice plugin – thanks!

    Can you tell me how to set up a delay so that the keyup function doesn’t fire so often?

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Si

    (@shopods)

    Figured it out. Edited psa_scripts.js and added a 500ms delay.
    FYI I replaced this:

    jQuery(‘#psa-search-form’).keyup(function(){
    var post_data = {
    ‘action’ : ‘ajaxnews’,
    ‘searchvar’: jQuery(‘#psa-search-form’).val()
    };
    //alert(post_data.searchvar);

    jQuery(‘#search-results’).html(‘<div class = “spinner-psa”></div>’);
    if (post_data.searchvar)
    {
    jQuery.post(protocol + “/wp-admin/admin-ajax.php”, post_data ,function(data){
    jQuery(‘#search-results’).html(data);
    });
    }

    return false;
    });

    with this:

    var delay = (function(){
    var timer = 0;
    return function(callback, ms){
    clearTimeout (timer);
    timer = setTimeout(callback, ms);
    };
    })();

    jQuery(‘#psa-search-form’).keyup(function(){
    delay(function(){
    var post_data = {
    ‘action’ : ‘ajaxnews’,
    ‘searchvar’: jQuery(‘#psa-search-form’).val()
    };
    //alert(post_data.searchvar);

    jQuery(‘#search-results’).html(‘<div class = “spinner-psa”></div>’);
    if (post_data.searchvar)
    {
    jQuery.post(protocol + “/wp-admin/admin-ajax.php”, post_data ,function(data){
    jQuery(‘#search-results’).html(data);
    });
    }

    return false;
    }, 500 );
    });

    leokoltm

    (@leokoltm)

    Hi.Is your plugin safe? I noticed that it does not use wp-nonce, which could slightly protect the site from dangerous requests

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Keyup Delay Search’ is closed to new replies.