陈言李语

聊聊网络,说说设计,侃侃生活

导航

寂寞也是一种动力 + Ajax

www.shanghai-translation-company.com上海翻译公司

因考虑种种原因,所以“轻装”来到上海,早已习惯以电脑为“伴”的我还真不习惯突然的失去...

还好过来之前考虑到了这点,带了几本书(第一本asp.net大全;第二本UML;第三书Ajax高级程序设计)打发时间(

说实在话这几本书买来一年多都没看过几次)...

最近看了Ajax高级程序设计 感觉这里面的内容很不错,不看真是太可惜了,就“强迫”自已看(这是一个很不喜欢看书的人)。我打算把学到

的Ajax很常用的东西分享给大家,说不定也能帮助到需要的人或增加点网站的流量.

这是一个《ajax 提示实例 》

适合用于:新邮件提示,新订单提示, 新评论提示 ...

注意提示的是:这里面的zXmlHttp 对象是 公共库 zxml.js 文件里的,由于本站不可上传附件,所以大家去网站下载个即可

<script>
var oXmlHttp=null;
var iInterval=5000;//检查的时间间隔(单位为毫秒)
var iLastCommentId=-1;//上次接收的评论ID
var divNotification=null;//显示提示信息的层

//提示:这是提示框方法调用
//sName 是名称
//sMessage 是内容
function showNotification(sName,sMessage)
{
 if(!divNotification)
 {
  divNotification=document.createElement("div");
  divNotification.className="notification";
  document.body.appendChild(divNotification);
 }
 
 divNotification.innerHTML="<strong>New Comment</strong><br/>"+sName+" says:"+sMessage+"<br /><a href=\"###\">View</a>";
 divNotification.style.scrollTop=document.body.scrollTop+document.body.clientHeight-100
 divNotification.style.scrollLeft=document.body.scrollLeft+document.body.clientWidth-100
 //alert(document.body.scrollLeft+document.body.clientWidth)
 divNotification.style.display="block";
 setTimeout(function(){divNotification.style.display="none"},3000);
}

//主方法 open执行打开info.aspx,结果返回三个值 如 1|| 2||3  
function checkComments()
{
 if(!oXmlHttp)
 {
  oXmlHttp=zXmlHttp.createRequest();
 }else if (oXmlHttp.readyState != 0) {
  oXmlHttp.abort();
 }
 
 oXmlHttp.open("get","../info.aspx",true);
 
 oXmlHttp.onreadystatechange=function() {
  if(oXmlHttp.readyState==4)
  {
   if(oXmlHttp.status==200){
    //alert(oXmlHttp.responseText)
    var aData=oXmlHttp.responseText.split("||");
    if (aData[0]!=iLastCommentId){
     if(iLastCommentId!=-1){
      showNotification(oXmlHttp.responseText,"");
      setTimeout(function(){checkComments()},iInterval);
      //alert(oXmlHttp.responseText)
    //  alert(aData[0])
    }
    iLastCommentId=aData[0];
    }
   }
  }
  
 };
 
 oXmlHttp.send(null);
 
}
window.onload=function() {
 if(zXmlHttp.isSupported){
  checkComments()
 }
}

</script>

//提示框的样式
<style>
.notification
{
 border:1px solid red;
 padding:10px;
 background:white;
 position:absolute;
 display:none;
 top:expression(offsetParent.scrollTop + offsetParent.clientHeight - 80);
 left:expression(offsetParent.scrollLeft + offsetParent.clientWidth - 150);
}
</style>

 ------------------------------------------------------------------------------------------------------------------------------------------------------------------
看到实例不清楚或有需要的朋友可以与我联系
(色丝线.)我的邮箱:119906938@qq.com 
                    Q  Q号:119906938

<< 网站优化解决方案以及网站优化分析建议(转)网络营销对传统行业的意义 >>

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最近发表

Powered By Z-Blog 1.8 Devo Build 80201 Copyright 突破力网络营销 SEO. Some Rights Reserved.