javascript-Bootstrap模式远程源错误处理

我们正在使用Bootstrap Modal窗口来显示一些通过远程源加载的html.我们通过使用Bootstrap文档中的推荐方法,通过使用remote选项并将其传递给url来执行此操作. (如here所述)

例如:

$('#id').modal({remote:'index.html'});

我的问题:如果index.html不可用,是否可以处理错误

我在文档中看不到任何答案.

我知道这种情况很少发生,但是如果某人的连接缓慢或参差不齐,我宁愿向他们显示一个错误,而不是仅仅挂着一个空的模态.

解决方法:

您可能想要在您的应用程序中实现一个全局Ajax错误处理程序,它将附加到执行的每个Ajax请求上,实现看起来像这样:

$( document ).ajaxError(function( event, jqxhr, settings, exception ) {
  //Since this handler is attach to all ajax requests we can differentiate by the settings used to build the request
  if ( settings.url == "index.html" ) {
    //Handle error
  }
});

您可以阅读有关Global Ajax Handlers here的更多信息.

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...