怎样使页面无刷新显示数据?

解决方案 »

  1.   

    nod wxqq2001(就让我用一生等待) 另外使用js调用webservice也可以
      

  2.   

    说了那么多 又没有人用过xmlhttp做过项目
      

  3.   

    to vivi8233(吐司)xmlhttp 不难啊,特别是显示个短信,朋友上线之类的消息很方便iframe不行,虽然是局部刷新,但还是要刷新
      

  4.   

    xmlhttp固然好,但是浏览器兼容性差,不过听说ASP.NET里面将会加入对xmlhttp的客户端-服务器通信支持。我建议使用的是iframe,隐藏使用。根据DOM标准,使用如下语句,你就能够用一个隐藏Frame来请求服务器端页面(Firefox 1.0测试通过):
    var oIFrame=document.createElement('iframe');
    oIFrame.contentWindow.location='TargetPage.aspx';
    但是很遗憾,就算是IE6对DOM的支持也不完全,在IE6里面一个iframe对象必须被添加到页面上才能够导航,也就是需要如下代码:
    var oIFrame=document.createElement('iframe');
    document.body.appendChild(oIFrame);
    oIFrame.style.display='none';
    oIFrame.contentWindow.location='TargetPage.aspx';(以上所有代码都是客户端javascript)
      

  5.   

    使用webservice.htc可以到这里下载: http://msdn.microsoft.com/workshop/author/webservice/webservice.htc
    建一个WebService 文件名为Service1.asmx: [WebService(Namespace="http://localhost/BehaviorService/")]
     public class TestService : System.Web.Services.WebService
     {    /// <summary>
      /// 返回服务器的时间
      /// </summary>
      [WebMethod]
      public string GetServerTime()
      {
       return DateTime.Now.ToString();
      }
     }在同级目录下进一个html文件,内容如下:<script>
    var intCallId = 0;function Init()
    {
     GetServerTime();
     setInterval("GetServerTime()",1000);
    }function GetServerTime()
    {
     Service.useService("Service1.asmx?WSDL","TestService");
     intCallId = Service.TestService.callService("GetServerTime");
    }function service_result()
    {
     if (event.result.error)
     {
      showresult.innerText = event.result.errorDetail.string;
     }
     else
     {
      showresult.innerText = event.result.value;
     }
    }</script>
    <html>
    <body onload="Init();">
    <div id="Service" style="behavior:url(webservice.htc)" onresult="service_result()"></div>
    <span id=showresult></span>
    </body>
    </html>通过这种方法就可以实现页面的局部刷新了