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

  • SEARCH
  • Home
  • 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 7966515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:26:55+00:00 2026-06-04T06:26:55+00:00

i have an input search like this: <input type=search autocomplete=off name=searchSchools id=searchSchools value= onKeyUp=searchSchools(this.value)

  • 0

i have an input search like this:

<input type="search" autocomplete="off" name="searchSchools" id="searchSchools" value="" onKeyUp="searchSchools(this.value)" />

As you can se, every time the onKeyUp event is fired i call a function named “searchSchools” where i search schools matching the current value of the input search in PHP and i return them in JSON format, the problem is that if i type fast more than one request is sent to the PHP page and i want to prevent this, i want to send the post request to the page only if there is no other request to the same page made by this function.

Here is the function:

function searchSchools(name){
    $.post("search-schools.php", { name: name },
    function(data) {
        //-> Here i do whatever with data returned
    }, 
    "json"
    );
}
  • 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-04T06:26:57+00:00Added an answer on June 4, 2026 at 6:26 am

    Add a delay in $.post.. Try like below,

    var timer = null, xhrReq = null;
    function searchSchools(name){
        if (timer != null) {
           clearTimeout(timer);
        }
    
        timer = setTimeout(function () {
            if(xhrReq != null) {
               xhrReq.abort(); //to kill all prev request and take the latest
            }
    
            xhrReq = $.post("search-schools.php", { name: name },
               function(data) {
                  //-> Here i do whatever with data returned
               }, 
               "json"
             );
        }, 1000); //will be posted only after 1 second.
    }
    

    Edit: Added xhr.abort() to abort any old request and consider only the latest..

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

Sidebar

Related Questions

I have a simple form like this: <form name=serachForm method=post action=/home/search> <input type=text name=searchText
I have an an ajax request that looks like this, $('input.fakecheck').click(function(){ alert(deleteing....); $.ajax({ url:/search,
I am working on autocomplete textbox. In this user can type their city name
I have the following code: $(#auto).autocomplete({ source: js/search.php, minLength: 3 }); This code is
OK so i have this script that submits the input of a search box
I have a search form that looks like this: The code behind the form
Supposedly in HTML5 in Safari, you can define your input type as search and
I get an JSON Array like this: [{type:user,id:12,name:Name of User},{type:group,id:9,name:Name of UserGroup}] The Backend
Say I have a simple form like this: <html> <head> <meta http-equiv=Content-Type content=text/html; charset=utf-8
I have form like this: <form method=POST action=<?php echo base_url() ?>admin/admin_search> <fieldset> <label for=nalozi>Nalozi</label><input

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.