views:

29

answers:

1

Suppose that I have an ASP.NET page, where a customer can select a product from a drop down list, and then with this change event, corresponding price, quantity etc. fields are changed and set to appropriate values. These values are obtained from server-side asp.net page using jquery's "$.post(....)" method. Now in the same page, there is another section, which shows live market statistics of the products. This section obtains the live market product values by making a request to the server-side asp.net page every 20 seconds interval, which is controlled using a timer.

Now suppose that this timer goes off and a request is being processed at the server. At the same time the customer selects a different product from the drop down list, which also fires another ajax request.

Is there any chance that the responses from these two different request can get mixed up? I mean the response which is intended for the live update section is considered as the response for the product catalog section? If that is the case, then before making an ajax request, how can I be sure that there is another request is being processed at the server, and if necessary, abort that request?

I don't want to use ASP.NET ajax for this situation, because it generates a lot of unnecessary script/data, which increases the page size, and the customers of this site has a bandwidth of 2-4 kbps.........................:|

+1  A: 

It depends how the code is written. So long as you aren't using globals in your JS you should be fine.

The first example at http://www.jibbering.com/2002/4/httprequest.html uses globals (xmlhttp), don't do that. Pass variables about instead. Make use of the this keyword inside your onreadystatechange callback function.

David Dorward
The question mentions that he's using jQuery and its `post()` method. That should take care of (avoiding) global XHRs automatically.
Max Shawabkeh
I am using jquery's built-in "$.post("scriptname.aspx, {..}, function(response){})" method, so I am not totally handling the request-response thing myself. My question is, if there is two types of requests like this at the same time, then is there any possibility that response for one request can be considered as the response for the other request?
Night Shade
No. You don't see browsers swapping images about at random. This is the same thing. TCP/IP isn't completely broken.
David Dorward
Well then, thank you david........ :)
Night Shade