开发者

Possibility of Ajax Response Mix-up

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开发者_JS百科, 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.........................:|


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜