ajax 超时

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<!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>
    <script type="text/javascript" src="prototype.js"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    <script type="text/javascript">
    function callInProgress(xmlhttp) {
  switch (xmlhttp.readyState) {
    case 1: case 2: case 3:
      return true;
      break;
    // Case 4 and 0
    default:
      return false;
      break;
    }
}function showFailureMessage() {
  alert('uh oh, it looks like the network is down.  Try again shortly');
}// Register global responders that will occur on all AJAX requests
Ajax.Responders.register({
  onCreate: function(request) {
    request['timeoutId'] = window.setTimeout(
      function() {
        // If we have hit the timeout and the AJAX request is active, abort it and let the user know
        if (callInProgress(request.transport)) {
          request.transport.abort();
          showFailureMessage();
          // Run the onFailure method if we set one up when creating the AJAX object
          if (request.options['onFailure']) {
            request.options['onFailure'](request.transport, request.json);
          }
        }
      },
      5000 // Five seconds
    );
  },
  onComplete: function(request) {
    // Clear the timeout, the request completed ok
    window.clearTimeout(request['timeoutId']);
  }
});
   
   
   
   
   
   
   
   
   
    //debugger;
    testAjaxRequest();
      function testAjaxRequest() {
        //$('testButton').disabled = 'true';
        var url = '/Default2.aspx';
        var myAjax = new Ajax.Request(
          url,
          {
            method: 'get',
            requestTimeout:1,
            onSuccess:showResponse ,
            onTimeout: function() {
        alert("onTimeout");
      },
            onComplete: function() {  },
            onException: function(e) { alert('onException(e): ' + e) }
          }
        );
      }
//$('testButton').disabled = ''
     

      function showResponse(originalRequest) {
        alert('showResponse: ' + originalRequest.responseText);
      }
      function pause(millisecondi)
      {
        var now = new Date();
        var exitTime = now.getTime() + millisecondi;

        while(true)
        {
            now = new Date();
            if(now.getTime() > exitTime) break;
        }
        alert("wan le");
      }
    </script>
    </div>
    </form>
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值