1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

stopping ajax calls

Discussion in 'Web Design & Development' started by cpscdave, Jul 9, 2010.

Thread Status:
Not open for further replies.
Advertisement
  1. cpscdave

    cpscdave Thread Starter

    Joined:
    Feb 25, 2004
    Messages:
    433
    Hi all

    I've written a function to do an autocomplete on some input forms
    Code:
    function getPartAutoComplete(str, field)
    {
    	ajax = getAjaxHandler();
    	
    	url = base + "parts/ajax_part_list/" + str +"/" + field;
    	ajax.onreadystatechange = function(){
    		if(ajax.readyState == 4){
    			document.getElementById("autoSuggestionsList_"+field).innerHTML=ajax.responseText;
    			//alert(ajax.responseText);
    		}
    	}
    	ajax.open("GET", url, true);
    	ajax.send(null); 
    }
    
    The problem is if the user types in a bunch of characters it does a bunch of searches that aren't actually used.

    EG:
    Say the user searches for drip.
    There will be a search on dri and drip and the first one gets ignored.

    Is there a way when it goes into the function to search for drip to kill hte dri search in progress?

    It's not really an issue on this site, I'm more curious for myself :)
     
  2. MMJ

    MMJ Guest

    Joined:
    Oct 15, 2006
    Messages:
    3,625
    try ajax.abort
     
  3. cpscdave

    cpscdave Thread Starter

    Joined:
    Feb 25, 2004
    Messages:
    433
    how can I tell when another ajax call has started?

    There is no concept of static varibles inside of Javascript so each seperate call will have it's on unique ajax handler
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/934570