假如说你在后台有订单,客户的需求是只要有订单后台就提示,这样的话,我们就要求页面必须得时时刷新,但是这样的缺点是如果页面时时刷新,那么当用户添加内容的时候,刚写一个字,页面就刷新没了,所以说我们不能让页面整体刷新,只能用到局部刷新,局部刷新的方法很多,个人认为ajax实现起来比较好,请看下面这个例子:
| 以下是包含页面,包含后台的第一个页面中ajax.asp: <script type="text/javascript"> <!-- //建立XMLHttpRequest对象 var xmlhttp; try{ xmlhttp= new ActiveXObject('Msxml2.XMLhttp'); }catch(e){ try{ xmlhttp= new ActiveXObject('Microsoft.XMLhttp'); }catch(e){ try{ xmlhttp= new XMLHttpRequest(); }catch(e){} } } function getPart(url){ xmlhttp.open("get",url,true); xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState == 4) { if(xmlhttp.status == 200) { if(xmlhttp.responseText!=""){ document.getElementById("partdiv").innerHTML = unescape(xmlhttp.responseText); } else { document.getElementById("partdiv").innerHTML = "数据载入出错"; } } } } xmlhttp.setRequestHeader("If-Modified-Since","0"); xmlhttp.send(null); } setInterval("getPart('ordersound.asp')",50000); //--> </script> <div id="partdiv" style="display:none;"></div> |
然后我们做一个订单查询页面,比较简单,都会做
| 新订单查询页面: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <body> |
这样就可以了,在家可以试试。。。
原载: No.1网络工作室 http://www.noonenet.cn/