惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Security @ Cisco Blogs
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Cisco Talos Blog
Cisco Talos Blog
Cyberwarzone
Cyberwarzone
SecWiki News
SecWiki News
Webroot Blog
Webroot Blog
L
LINUX DO - 最新话题
V
Vulnerabilities – Threatpost
T
Troy Hunt's Blog
Cloudbric
Cloudbric
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
H
Heimdal Security Blog
S
Schneier on Security
NISL@THU
NISL@THU
The Hacker News
The Hacker News
Attack and Defense Labs
Attack and Defense Labs
A
Arctic Wolf
V2EX - 技术
V2EX - 技术
Security Latest
Security Latest
AWS News Blog
AWS News Blog
Scott Helme
Scott Helme
W
WeLiveSecurity
S
Secure Thoughts
Y
Y Combinator Blog
GbyAI
GbyAI
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - Franky
量子位
人人都是产品经理
人人都是产品经理
雷峰网
雷峰网
K
Kaspersky official blog
P
Privacy & Cybersecurity Law Blog
T
Tenable Blog
The GitHub Blog
The GitHub Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
J
Java Code Geeks
Vercel News
Vercel News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Schneier on Security
Schneier on Security
云风的 BLOG
云风的 BLOG
小众软件
小众软件
Engineering at Meta
Engineering at Meta
宝玉的分享
宝玉的分享
C
CERT Recently Published Vulnerability Notes
Security Archives - TechRepublic
Security Archives - TechRepublic
C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Palo Alto Networks Blog

博客园 - s80895304

win8 framework3.5安装 ChangeCharToTable sql 触发器 mysql 备忘sql ActiveMQ 安装 【转】j2ee 环境搭建 C#原始类型扩展方法—this参数修饰符 消息队列(Message Queue)简介及其使用 Web Service 身份验证 sql 索引 Memcached、MongoDB、Redis和tokyotyrant 【转】ActiveMQ redis iphone 技巧 10款iOS高效开发必备的Objective-C类库 ASIHTTPRequest jquery 倒计时插件 Queue 队列 写日志简单应用 js keycode
IE中同一个url第二次AJAX调用无法触发onreadystatechange事件
s80895304 · 2011-11-25 · via 博客园 - s80895304

如果第二次通过XMLHttpRequest去请求一个URL,则不会触发onreadystatechange时间,虽然从调试插件来看,ie是进行了这次请求。

后来发现,这个是因为在ie下,如果请求的URL已经被浏览器cache,则调用send方法以后,xhr的readyState已经成为了4,即 一开始就是请求完成的状态,当然以后readystate不会再被赋值,也不会触发onreadystatechange事件。

解决办法:在调用send后立即检查xhr的readystate,如果已经结束,则直接处理,不必再等待onreadystatechange事件。

  1. getJSON : function(url, callback, onerror) {   
  2.     var xhr = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();  
  3.     onerror = $X.isFunction(onerror) ? onerror : null;  
  4.     xhr.open('GET', url, true);  
  5.     xhr.setRequestHeader("X-Requested-With""XMLHttpRequest");  
  6.     xhr.send();  
  7.     var f = function() {  
  8.         if (xhr.readyState == 4) {    
  9.             if (xhr.status == 200) {    
  10.                 try {   
  11.                     var data = eval('('+xhr.responseText+')');  
  12.                 } catch (e){  
  13.                     onerror && onerror();   
  14.                     xhr = null;  
  15.                     return;  
  16.                 };  
  17.                 callback(data);  
  18.             } else {  
  19.                 onerror && onerror();  
  20.             }  
  21.             xhr = null  
  22.         }  
  23.     };  
  24.     if (xhr.readyState == 4) {   
  25.         f();  
  26.     } else {  
  27.         xhr.onreadystatechange = f;  
  28.     }  

  http://www.iteye.com/topic/467019