Dojo需要连接错误,当模块加载失败时 [英] Dojo require, connect to error when module failed loading

查看:139
本文介绍了Dojo需要连接错误,当模块加载失败时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试加载不存在的模块时,它会失败,404错误(当然)。我想要处理这个错误,但不知道如何连接到错误事件。



根据Dojo文档,我应该可以使用其微型事件api



这个代码不起作用。

  var handle = require.on('error',function(error)
{
alert('Finally error')
});

require(['notxistent / module'],function(m)
{
alert('Module was loaded正确')
});

Dojo版本是1.7.1,浏览器最新的Chrome。

解决方案

有关这个文件的文档有点好奇。在错误的xhr需要之后,只能在异步模式下,只有使用Dojo的dev版本,才能在短暂超时(dojoConfig.waitSeconds)之后触发error事件。

>

为什么?那么只有异步模式引发了这个事件,看起来CDN的构建是用dojo-timeout-api == 0构建的。



你可以使用自己的定制SDK)版本的Dojo?



@mschr - 如果您使用Dojo(夜间)而不是Dojo 1.7.2,您的jsfiddle示例可以工作 - 与上述相同的原因。 >

When I try to load nonexistent module, it fail with 404 error (of course). I want to handle this error but don't know how to connect to "error" event.

According to Dojo doc, I should be able to do that using its micro event api.

This code does not work.

var handle = require.on('error', function( error )
                 {
                     alert('Finally error')
                 });

require(['nonexistent/module'], function ( m )
{
     alert('Module was loaded correctly')           
});

Dojo version is 1.7.1, browser latest Chrome.

解决方案

The documentation on this one is a bit curious. I can get the 'error' event to fire after a short timeout (dojoConfig.waitSeconds) after a failed xhr require, but only in async mode, and only with a dev build of Dojo.

Why? Well, only async mode raises the event, and it looks like the CDN build was built with dojo-timeout-api == 0.

Can you use your own custom (SDK) version of Dojo?

@mschr - your jsfiddle sample works if you use Dojo (nightly) instead of Dojo 1.7.2 - same reason as above.

这篇关于Dojo需要连接错误,当模块加载失败时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆