【问题标题】:ajax error handler when internet connection lost互联网连接丢失时的 ajax 错误处理程序
【发布时间】:2013-03-28 12:05:52
【问题描述】:

我有一些 ajax 调用,我想在其中添加处理程序以防出错。我找到了“错误”处理程序,但它不起作用,即 当互联网连接丢失时。这些情况是否有第二个处理程序?

$.ajax({
      type: "GET",
      url: "dosomethink.php",
      success: function (data) {
        $('#abc').html(data);
      },
      error: function (xhr, ajaxOptions, thrownError) {
        alert(xhr.status);
        alert(thrownError);
      }
    });

【问题讨论】:

  • 您是如何排除互联网连接丢失的问题的?
  • @Thomas1703 您可以使用超时来解决连接丢失问题。
  • 为什么不使用 navigator.onLine 或 XHR 请求?

标签: javascript ajax jquery error-handling


【解决方案1】:

如果你使用超时和错误方法会怎样

$.ajax({type: 'GET',url: '/controller/action',timeout: 15000,success: function(data) {},error: function(XMLHttpRequest, textStatus,errorThrown) {}});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-24
    • 1970-01-01
    • 2013-09-02
    • 1970-01-01
    • 2012-11-17
    相关资源
    最近更新 更多