通过 Microsoft.XMLDOM 实现简单的 Ajax(更新)
今天在在做公司的搜索关键词功能,因为哪个页面要做成静态 HTML 的,所以想了几个方法,昨天晚上快下班的时候上头才说要改,就急急忙忙地改了一下,实现的方法是用
来读这些动态的数据,但是因为页面上搜索有条件,切换条件是直接用 js 来处理的,所以,在切换的时候,热门关键词都要跟在改变。但问题随之而来! 这个区域我没有办法在页面不刷新的情况下重新调用它。所以一直没有解决。
今天试着被调用的态页面反回 XML 结构的,再用 Js 去读这个结果,再输入,果然成功了。呵呵,也就是一个简单的 Ajax 应用。
动态页面生成 XML 的代码:




































返回的 XML 代码结构:
<keywords>
<item>
<word>关键词 1word>
<type>1type>
item>
<item>
<word>关键词 2word>
<type>2type>
item>
<item>
<word>关键词 2word>
<type>2type>
item>
<item>
<word>关键词 4word>
<type>4type>
item>
<item>
<word>关键词 5word>
<type>5type>
item>
keywords>
<item>
<word>关键词 1word>
<type>1type>
item>
<item>
<word>关键词 2word>
<type>2type>
item>
<item>
<word>关键词 2word>
<type>2type>
item>
<item>
<word>关键词 4word>
<type>4type>
item>
<item>
<word>关键词 5word>
<type>5type>
item>
keywords>
Javascript 读取的方法,FileName 参数是被调用的动态页面,panelID 是最终要显示的区域 ID 名称
重点:xmlDoc.async=”false”; 异步方式读取

































HTML 调用的代码:
//说明:
//现在以上面的 动态页面命名为 ”getkeyword.aspx“ ,Javascript 存成 Script.js
//HTML 调用时的例子
<script type=”text/javascript” src=”script.js”>script>
<div id=”panelKeyword”>
这个地方会显示最终的关键词
div>
<script type=”text/javascript”>
ReadKeywords(”getkeyword.aspx”,”panelKeyword”);
script>
//现在以上面的 动态页面命名为 ”getkeyword.aspx“ ,Javascript 存成 Script.js
//HTML 调用时的例子
<script type=”text/javascript” src=”script.js”>script>
<div id=”panelKeyword”>
这个地方会显示最终的关键词
div>
<script type=”text/javascript”>
ReadKeywords(”getkeyword.aspx”,”panelKeyword”);
script>
提醒一下:HTML 与 XML 里面的代码可能会有错别字的地方,因为是用记事本打出来的,如果真的有错的地方,请大家多多包涵..本文主要是讲的方法,而不是给代码,代码拿来也没什么用,网上好的 Ajax 框架多着呢,呵呵
应用效果:http://www.uctoy.com