返回列表 发帖

[其他] 实现无刷新加载数据(asp+ajax)

<div id="newphotos">数据载入中……</div>
<script language="JavaScript">
function getXML(URL){
         if (window.XMLHttpRequest)
        {
            var xmlhttp = new XMLHttpRequest();
        }
        else
        {
            var MSXML = ['MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];
            for(var n = 0; n < MSXML.length; n ++)
            {
                try
                {
                    var xmlhttp = new ActiveXObject(MSXML[n]);
                    break;
                }
                catch(e)
                {
                }
            }
   }
        xmlhttp.Open("GET", URL, false);
        try{
                xmlhttp.Send();
                var result = xmlhttp.status;
        }
        catch(e){
                return(false);
        }
        if(result==200){
               newphotos.innerHTML=unescape(xmlhttp.responseText);
        }
        var xmlhttp = null;
}

function update(){
         getXML('ajaxserver/newphoto.asp?placeid=<%= placeid %>&placecityid<%= placecityid %>');
}
setInterval("update()",1000);
</script>

asp文件
newphoto.asp
<!--#include file="include.asp" -->
<%
placeid=Request("placeid")
placecityid=Request("placecityid")
xmlhttp=""
xmlhttp=xmlhttp&"<table width=""99%"" height=""149"" border=""0"" align=""right"" cellpadding=""3"" cellspacing=""0"" class=""fuangkuanghs"">"&chr(13)
xmlhttp=xmlhttp&"<tr>"&chr(13)
xmlhttp=xmlhttp&"<td valign=""top""><table width=""100%"" border=""0"" cellpadding=""0"" cellspacing=""0"">"&chr(13)
xmlhttp=xmlhttp&"<tr>"&chr(13)
xmlhttp=xmlhttp&"<td height=""20"" align=""left"" class=""textblue""><table width=""396"" border=""0"" cellspacing=""0"" cellpadding=""0"">"&chr(13)
xmlhttp=xmlhttp&"<tr>"&chr(13)
xmlhttp=xmlhttp&" <td width=""65%""><a href=""http://www.jiluyisheng.com/photo.asp?placeid="&placeid&"&placecityid="&placecityid&"""><img src=""images/index/index_01.jpg"" width=""349"" height=""23"" border=""0""></a></td>"&chr(13)
xmlhttp=xmlhttp&"<td width=""35%""><a href=""http://www.jiluyisheng.com/photo.asp?placeid="&placeid&"&placecityid="&placecityid&""" target=""_self""><img src=""images/index/index_02.jpg"" width=""47"" height=""23"" border=""0""></a></td>"&chr(13)
xmlhttp=xmlhttp&"</tr>"&chr(13)
xmlhttp=xmlhttp&"</table>"&chr(13)
xmlhttp=xmlhttp&"</td>"&chr(13)
xmlhttp=xmlhttp&"</tr>"&chr(13)
xmlhttp=xmlhttp&"<tr>"&chr(13)
xmlhttp=xmlhttp&"<td valign=""top""><table width=""100%"" border=""0"" cellpadding=""0"" cellspacing=""0"">"&chr(13)
xmlhttp=xmlhttp&"<tr>"&chr(13)
set rs=userconn.execute("select top 3 weburl,photo_name,Photo_smallimg,idx_photo,jiuid,hits from v_jiphoto where weburl<>''  and  iflag=2 and priv=1 "&where_str&" order by idx_photo desc")
'set rs=userconn.execute("select top 5 * from jiphoto where weburl<>'' and systype=5 order by idx_photo desc")
  if not rs.eof then
do while not rs.eof
   weburl=rs("weburl")

  if weburl<>"" then
   web= Replace(weburl,"http://","")
picurl=weburl&"/Uploadfile/"&web& "/Photo/smallimg/" &  rs(";Photo_smallimg")
  else
  picurl="images/h3.gif"
  end if
xmlhttp=xmlhttp&"<td height=""25"" align=""center""><table width=""99%"" border=""0"" cellpadding=""0"" cellspacing=""0"">"&chr(13)
xmlhttp=xmlhttp&"<tr>"&chr(13)
xmlhttp=xmlhttp&"<td height=""12"" align=""center""><table width=""123"" height=""93"" border=""1"" cellpadding=""3"" cellspacing=""0"" bordercolor=""#cccccc"" style=""BORDER-COLLAPSE: collapse"">"&chr(13)
xmlhttp=xmlhttp&"<tr>"&chr(13)
xmlhttp=xmlhttp&"<td width=""123"" height=""93"" align=""center""><a target=blank href="&weburl&"/photo.asp?idx_photo="&rs("idx_photo")&"&jiuid="&rs("jiuid")&"><img src="&picurl&" javascript:DrawImage(this,115,67)"" alt=""点击看大图"" width=""115"" height=""67"" border=""0""/></a> </td>"&chr(13)
xmlhttp=xmlhttp&"</tr>"&chr(13)
xmlhttp=xmlhttp&"</table>"&chr(13)
xmlhttp=xmlhttp&"</td>"&chr(13)
xmlhttp=xmlhttp&"</tr>"&chr(13)
xmlhttp=xmlhttp&"<tr>"&chr(13)
xmlhttp=xmlhttp&"<td height=""12"" align=""center"">"&FilterString(Rs("photo_name"),9)&"("& Rs("hits")&"/"&;P.Get_RsCount(userconn,"[JiPhoto_reply]","idx_Photo="&rs("idx_photo"))&")</td>"&chr(13)
xmlhttp=xmlhttp&"</tr>"&chr(13)
xmlhttp=xmlhttp&"</table></td>"&chr(13)
Rs.MoveNext
loop
end if
rs.close()
set rs=nothing
xmlhttp=xmlhttp&"</tr>"&chr(13)
xmlhttp=xmlhttp&"</table></td>"&chr(13)
xmlhttp=xmlhttp&"</tr>"&chr(13)
xmlhttp=xmlhttp&"</table></td>"&chr(13)
xmlhttp=xmlhttp&"</tr>"&chr(13)
xmlhttp=xmlhttp&"</table>"&chr(13)
Response.write(escape(xmlhttp))
%>
天行健,君子以自强不息
地势坤,君子以厚德载物
黑色海岸线欢迎您

QQ群:7212260
致力于探索WEB技术精髓:http://www.bitechcn.com
点这里加我!

返回列表 回复 发帖