【问题标题】:How to detect and handle 404 error with Sammy.Template?如何使用 Sammy.Template 检测和处理 404 错误?
【发布时间】:2013-04-14 05:26:48
【问题描述】:

我使用 Sammy.js 从路由中加载模板名称,但如果找不到该文件,我想将用户重定向到另一个页面。基本上,我有:

this.use(Sammy.Template, 'tpl');

this.get('#/:page', function() {

    // render a template
    // this.load()

    this.render('templates/' + this.params['page'] + '.tpl').swap();
});

如何处理 404 错误?

【问题讨论】:

    标签: javascript jquery http-status-code-404 sammy.js


    【解决方案1】:

    由于您可以使用带有传递选项的负载,我会这样做(在我的脑海中。可能存在语法错误,但逻辑是存在的):

    this.load('templates/' + this.params['page'] + '.tpl', {error: function(response) { ... handle error }).interpolate(null, location).swap();
    

    在错误函数中做404检查。

    【讨论】:

      猜你喜欢
      • 2011-06-10
      • 2012-07-27
      • 2011-11-20
      • 2012-11-23
      • 2012-04-20
      • 2013-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多