This time I will bring you what are the methods of ajax to achieve partial refresh, and what are the precautions for ajax to achieve partial refresh. The following is a practical case, let's take a look.
ajax partial refresh
<script> setInterval("refreshTime()",1000); //每格1秒刷新一次 funciton refreshTime() { var dateObj = new Date(); time.innerHTML = dateObj.toLocaleDateString(); //刷新p里面的内容 } </script> <p id=time> </p>
function doRef() { var url = "xxx.aspx" var dateRequest = new ActiveXObject("Microsoft.XMLHTTP"); dateRequest.abort() ; dateRequest.open( "GET", url , true ); dateRequest.onreadystatechange = onSendSelf ; dateRequest.send() ; function onSendSelf() { if( dateRequest.readyState != 4 ) { return ; } var theDate = dateRequest.responseText ;//如果出现编码问题,可以在服务端escape一下,然后在这里使用unescape( responseText ) thep.innerHTML = theDate ; } } setInterval( doRef , 1000 ) ;//1秒刷新一次,有点快
<form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <br /> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick"> </asp:Timer> <asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox> </ContentTemplate> </asp:UpdatePanel> </form>
======Timer1_Tickeventadded in the background Up
// Interval="1000" is to set the refresh time intervalTextBox1.Text=DateTime.NowYou will understand after taking a look I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website! Recommended reading:Use Blod to make ajax progress bar download
The above is the detailed content of What are the ways to achieve partial refresh in ajax?. For more information, please follow other related articles on the PHP Chinese website!