【发布时间】:2017-03-30 09:56:50
【问题描述】:
我正在尝试加载一个需要 jquery 才能工作的插件jquery.countdown
在我的初始化类上调用插件时出现此错误:
GET http://localhost:3008/js/jquery.js404(未找到)
require.js:166 未捕获的错误:jquery(…) 的脚本错误
这是我的起始代码:
define(function (require) {
var commons = require('commons'),
core = require('core/core_library'),
$ = require('vendor/jquery'),
ButtonStatus = require('module-pf/ButtonStatus'),
Archive = require('module-pf/Archive'),
Countdown = require('appvendor/jquerycountdown');
});
于是我开始调查。首先, jquery.countdown 库操作系统正确加载,正如调试所说:
所以我猜require 不知道这些库的加载顺序。经过一番研究,我发现您可以嵌套依赖项来对它们进行排序:
define(['commons'], function () {
require(['vendor/jquery'], function (commons) {
//Added this for testing by calling jquerycountdown internal funcionality
require(['appvendor/jquerycountdown'], function (inyectedCountdown) {
$('#timer').countdown('2020/10/10', function (event) {
$(this).html(event.strftime('%D days %H:%M:%S'));
});
});
});
});
但我仍然遇到同样的错误。我不知道发生了什么,也许是不兼容的 jquery 版本?我手动添加了那个库。 Jquery 在我的项目中运行良好,但它正在加载两个实例,一个位于 js/jquery (404) 中,第二个位于 vendor/js/jquery (200) 中。
【问题讨论】:
-
jquery.js 未加载 - 您提供的 URL 返回 404
-
http://localhost:3008/js/jquery.js 404 (Not Found)这是这里唯一重要的事实。
标签: javascript jquery node.js require