AJAX刷新方法? [英] AJAX Reload Method?

查看:105
本文介绍了AJAX刷新方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个我试过重新加载页面,而无需刷新[AJAX ...],但似乎并不奏效:/

I tried this to reload the page without refreshing [AJAX...], but doesnt seem to be working :/

function refresh() {
   link = document.location;
   xmlhttp=new XMLHttpRequest();
   xmlhttp.onreadystatechange=function() {
      if (xmlhttp.readyState==4 && xmlhttp.status==200) {
         document.getElementsByTagName('table').innerHTML=xmlHttp.responseText;
      }
   }
   xmlhttp.open("GET",link,true);
   xmlhttp.send();
}

任何人都知道什么是错的?

Anyone know what's wrong?

推荐答案

不要使用innerHTML的,它是一个专用的Microsoft JScript中的方法不正确地注册了DOM。在举例来说,如果你用它来导入元素的ID它不太类似于把一个皇冠上的女王头,更像是倾销机构由一个桥,可能会或可能不会看到它,可能不会。坚持使用importantNode使用AJAX和你的AJAX加载的内容将工作可靠。另外code不是文字,不要用responseText的,使用responseXML的。然后,而不必重新请求相同的内容,你可以简单地取消隐藏,除非你期望的内容已在几秒钟在这种情况下,你可以删除元素和重做过去X次更新的是已经在DOM层AJAX请求。看到我的视频的视觉演示...

Don't use innerHTML, it's a proprietary Microsoft Jscript method that doesn't properly register the DOM. In example if you use it to import an element with an ID it's less akin to putting a crown on a queen's head and more akin to dumping bodies by a bridge, the may or may not have seen it, likely not. Stick to using importantNode with AJAX and your AJAX loaded content will work reliably. Also code is not text, do not use responseText, use responseXML. Then instead of having to re-request the same content you can simply unhide the layer that is already in the DOM unless you expect the content to have been updated in the past X number of seconds in which case you can delete the element and redo the AJAX request. See my video for a visual demonstration...

http://www.youtube.com/watch?v=-iVebYrrz9U

这篇关于AJAX刷新方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆