日期:2014-05-18  浏览次数:20488 次

请教ajax的基本顺序问题
为什么我在网上看到ajax中的
xmlHttp.onreadystatechange=function(){.....}要放在open、send前面?

onreadystatechange不是仅仅在客户端指定响应函数么?

而我把xmlHttp.onreadystatechange放在send后面,照样可以运行呀。那么为什么说“xmlHttp.onreadystatechange

要放在open、send前面?”
-------------------------------------
xmlHttp.open("GET","time.aspx",true) // 1
xmlHttp.send(null); // 2 
xmlHttp.onreadystatechange=function(){。。。。} // 3

就是这3句话的顺序问题。

------解决方案--------------------
探讨
引用:
你放在xmlHttp.open前面的话就能处理所有状态

如果你放到send后面,则只能处理3-4的状态了



不对,我刚测试了,2 也能执行 , 1能不能我不晓得,忘了测试了。。。