Ajax - timer

P

Peter

I have the following code where when user types in the txtName textbox the program retrieves list of names from a database, the problem is this occurs after every key stroke. So if I want to look for Microsoft and I type 'Mic' the program will perform 3 searches with the first one being the longest because it would retrieve all of the names starting with 'M'. What I want to be able to do is if a user types 'Mic' without pausing the computer would wait until there's a pause in typing before performing a search.

What would I have to do to make this happen, how can I create some king of timer in JScript - my JScript knowledge is limited?

Thank You

Peter

Here's my code

//////////////// C# - ASP.NET 1.1 //////////////////////////////

this.txtName.Attributes.Add("onkeyup", "return GetList();");



//////////////// JScript //////////////////////////////

function GetList()
{
try
{
obj = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
obj = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e1)
{
obj = null;
}
}
if(obj!=null)
{
document.body.style.cursor = 'wait';

obj.onreadystatechange = ProcessResponse;
obj.open("GET", "http://mywebsite.com=" + document.getElementById("txtName").value, true);
obj.send(null);

document.body.style.cursor = 'default';
}
return false;
}
 
W

Wei-Dong XU [MS]

Hi Peter,

Thanks for the posting at the newsgroup!

"pausing the computer would wait until there's a pause in typing before
performing a search."
I understand this is really one performance issue for the customer at
typing. Each query (search) to the server when customer type one letter is
a performance hit to this issue. So currently I have two suggestions for
you that:

1. At the first typing, please query the database to perform the query
retrieving the phrase/word with the first letter as the customer typed.
Store the search result at the client web page. Then for other letters
inputted by the customer, we only need to search the local search result to
provide the phrase/word for the customer's reference.

This will only need one query to the server side and there is no need for
us to perform the follow-up queries because all the phrases/words are
stored at the client side after the customer typed the first letter.

2. if your phrase/word database is not very huge, you could directly send
all the data to the client web page. Then we only need to query the data at
the client side. There is no any query required after the page load. This
will give the customer one Web UI performance as the same as in desktop
windows.
Please note, if your database is very huge, this is not very approciate for
you.

Please feel free to let me know if you have any further question on this
issue. Have a nice day!

Best Regards,
Wei-Dong Xu
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=====================================================
Business-Critical Phone Support (BCPS) provides you with technical phone
support at no charge during critical LAN outages or "business down"
situations. This benefit is available 24 hours a day, 7 days a week to all
Microsoft technology partners in the United States and Canada.
This and other support options are available here:
BCPS:
<https://partner.microsoft.com/US/technicalsupport/supportoverview/40010469>

Others: <https://partner.microsoft.com/US/technicalsupport/supportoverview/>
If you are outside the United States, please visit our International
Support page:
<http://support.microsoft.com/default.aspx?scid=/international.aspx>.
=====================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top