Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ajax with settimeout

Status
Not open for further replies.

Andyfives

Programmer
Feb 22, 2002
46
DK
Hi,

I am working on a project that I will try and explain.. we want to offer currency conversion on our payment page dependent on the origin of the users credit card. We have to connnect to a remote service sending some data and in return retrieve data back.

This AJAX operation is controlled by obtaining 6 digits worth of credit card info (enough to test the country of the card). If this data changes in anyway we should go through with the request to the remote service.

All this works just fine. Now I want to know if I have programmed this in the best way. The response generally takes a split second to return.. but there might be occasions when this is slower.

I had initially an onKeyPress event on the input text box but there was a slight delay in the update so angled my solution towards using a poll event instead with setTimeout logic that would trigger every 5 seconds checking if there is any change to the 6 digit credit card field.

Is this the best way I can do this? I am concerned that if my setTimeout runs every 5 seconds and the call to remote computer takes longer I'm going to get some strange events happening.

Thanks guys/gals
 
You could call it on the onchange event of the textbox instead. This would mean that it's only called once - when the textbox loses focus. Another option is to use onkeyup and pop up a sort of modal wait box every time you are running the ajax request.

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
 
thanks for your response. seems my polling event is still behaving itself. I will keep monitoring, but its good to have a different perspective.

I have been able to control my remote call (written in core perl) so that even when it fails it is only "busy" for about 1 second if it can not connect. This is an improvement from the 30 seconds it was taking when I wrote my question.

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top