开发者

AJAX: If you set the async to false will the whole page reload?

Does teh whole page reload when this is s开发者_JAVA技巧et to false?

My main question is what the asynchronous does. yes i know what the word means but what does it do in code?

xmlhttp.open("GET","ajax_info.txt",true);


The word "asynchronous" is best described as "done in the background" in this context. It means that if you set this parameter to true, the request will be sent in the background and the user will be able to continue interacting with the page. If you set it to false, the page will BLOCK and the user won't be able to do anything until the request returns.

Note that this is different from the whole page reloading. The amount of traffic going over the wire is still much smaller than the whole page reload, so many of the AJAX benefits are preserved.

One reason why you might want to use synchronous (blocking) AJAX requests is when there's nothing to really do on the page while the request is loading.

BTW, since we're already on this subject: I encourage you to use a javascript framework for your AJAX needs. jQuery is fantastic. Don't use the XMLHttpRequest object directly.


Having used jQuery's ajax I found some issues with IE compatibility, so if you have to support IE6, it may be a good idea to avoid that and use straight JS.

Here's a good tutorial on it: http://daniel.lorch.cc/docs/ajax_simple/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜