Ajax长轮询
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Ajax长轮询,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2443字,纯文字阅读大概需要4分钟。
内容图文
前台代码:
<% @ Page Language = " C# " AutoEventWireup = " true " CodeBehind = " Wait.aspx.cs " Inherits = " Web监听.Wait " %> <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > < html xmlns ="http://www.w3.org/1999/xhtml" > < head runat ="server" > < title ></ title > < link href ="/JS/easyui/easyui.css" rel ="stylesheet" type ="text/css" /> < script src ="/JS/jquery.min.js" type ="text/javascript" ></ script > < script src ="/JS/easyui/jquery.easyui.min.js" type ="text/javascript" ></ script > < script src ="/JS/SimpoWindow.js" type ="text/javascript" ></ script > < script type ="text/javascript" > var longPollingCount; $( function () { longPollingCount = 1 ; $( " #msg " ).html( " 第 " + longPollingCount + " 次请求...... " ); longPolling(); }); function longPolling() { $.ajax({ type: " POST " , url: " Check.aspx?action=check " , dataType: " text " , timeout: 5000 , error: function (XMLHttpRequest, textStatus, errorThrown) { longPollingCount ++ ; $( " #msg " ).html( " 第 " + longPollingCount + " 次请求...... " ); if (textStatus == " timeout " ) { // 请求超时 longPolling(); // 递归调用 } else { // 其他错误,如网络错误等 $( " #msg " ).html(textStatus); longPolling(); } }, success: function (data, textStatus) { var parent = SimpoWin.GetWinParent(); $( " #txt " ).html( " 操作完成...... " ); $( " #txt " ).css( " color " , " red " ); setTimeout( function () { SimpoWin.closeWin(); parent.next(data); }, 1000 ); } }); } </ script > </ head > < body style ="background-color: White;" > < form id ="form1" runat ="server" > < div id ="txt" style ="text-align: center; vertical-align: middle; margin-top: 20px; margin-bottom: 20px; font-weight: bold;" > 请等待...... </ div > < div id ="msg" style ="text-align: center; vertical-align: middle;" > </ div > </ form > </ body > </ html >
后台代码:
using System; using System.Threading; namespace Web监听 { public partial class Check : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string action = Request["action"]; switch (action) { case"check": while (true) { if (Common.flag < 160) { Common.flag++; Thread.Sleep(100); } else { Response.Write("操作完成返回信息"); Response.End(); break; } } break; } } } }
原文:http://www.cnblogs.com/s0611163/p/4122911.html
内容总结
以上是互联网集市为您收集整理的Ajax长轮询全部内容,希望文章能够帮你解决Ajax长轮询所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。
来源:【匿名】