Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8894487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:30:35+00:00 2026-06-14T23:30:35+00:00

I have this jquery ajax call that is trigger on keyup . It has

  • 0

I have this jquery ajax call that is trigger on keyup. It has error handling which (with Firefox for e.g.) is triggered multiples times if the user enters keystrokes fast. Is there a quick way to stop multiple alert windows to be shown?

$('input[name$="_LOC"]').keyup(function(){

    if ($(this).val().length >=4){

        $.ajax({
            type: 'POST',
            url: 'red.asp?q='+$(this).val(),
            beforeSend: function() {
                    [...]   
            },
            success: function(data) {
                [...]
            },
            error: function() {
                alert("Oops!")
            }
        }); 
    }
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:30:36+00:00Added an answer on June 14, 2026 at 11:30 pm

    Restart a timer each time the onkeyup is triggered, this means the event only happens when the user has finished typing (or, at least, paused for a second or whatever).

    Use timer = setTimeout(yourFunction, yourDelay);

    To rest the timer user clearInterval(timer) and start the setTimeout again.

    var typing = false;
    var timer;
    
    $('input[name$="_LOC"]').keyup(function(){
     if(typing) {
       clearInterval(timer);
    
     }
    timer = setTimeout(sendAjax, 500, [this]);
     typing=true;
    });
    
    function sendAjax(element) 
    {
        if ($(element).val().length >=4){
    
            $.ajax({
                type: 'POST',
                url: 'red.asp?q='+$(element).val(),
                beforeSend: function() {
                        [...]   
                },
                success: function(data) {
                    [...]
                },
                error: function() {
                    alert("Oops!")
                }
            }); 
        typing = false;   
       }
    

    Here’s JSFiddle example: http://jsfiddle.net/X8US5/, you’ll need your browsers console.log viewer ready to see stuff (otherwise edit the console.logs to be alerts though they interrupt JS so times will be off)

    Edit:
    IE9 compatible (hack) version http://jsfiddle.net/5ndM5/1/
    Tried to find a jQuery alternative but none it seems.
    THe overriding the function alternative is good if you don’t want the global var, but if you only plan to use this code on one form then the global is acceptable (JS code is usually rife with them by accident anyway)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A situation I ran across this week: we have a jQuery Ajax call that
I have a web service that returns this string via the jQuery $.ajax() call
On my main page I have this jquery code which does an ajax call
I have a jQuery AJAX call with type:'GET' like this: $.ajax({type:'GET',url:'/createUser',data:userId=12345&userName=test, success:function(data){ alert('successful'); }
I have this jQuery ajax navigation tabs plugin that I created using some help
I have a dropdown list which is populated via a jquery ajax call when
Hei guys i have this JQuery Ajax call from my view and it looks
I have this jQuery code: $(document).ready(function() { $.ajax({ url: pages/+page+.php, cache: false }).done(function( html
I have this jQuery script var dataString = class_id=+class_id; $.ajax({ type: POST, url: page.php,
I have this Javascript/JQuery code: <script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js></script> <script type=text/javascript> name = $(#name).val(); alert(Name:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.