javascript - 简单的 cometd 应用程序 "org is not defined"

标签 javascript jquery comet

我正在尝试将旧的 cometd javascript 包装器和测试客户端(是 1.3.x)更新到较新的 comet 2.5.1 javascript 实现。我拥有所有依赖项并且浏览器可以找到它们,但我在 Firebug 的控制台中收到错误消息(见下文) Multiple errors about "org"

我的 HTML 头部如下:

<head>
    <title>CometD Tester</title>
    <link rel="stylesheet" type="text/css"href="style/style.css" />
    <script type="text/javascript" src="org/cometd/Cometd.js"></script>
    <script type="text/javascript" src="org/cometd/AckExtension.js"></script>
    <script type="text/javascript" src="org/cometd/ReloadExtension.js"></script>
    <script type="text/javascript" src="jquery/jquery-1.9.0.js"></script>
    <script type="text/javascript" src="jquery/jquery.cookie.js"></script>
    <script type="text/javascript" src="jquery/jquery.cometd.js"></script>
    <script type="text/javascript" src="jquery/jquery.cometd-reload.js"></script>
    <script type="text/javascript" src="js/myCometd.js"></script>
</head>

所有这些都是浏览器发现的。查看 Cometd.js 我看到以下内容:

org.cometd.Cometd = function(name)
{
 ....
}

那么这不是定义 org 吗?请注意,控制台中的所有错误都不是来自 Cometd.js。否则我看不到“org.cometd”的其他定义。如果有人能帮助我,我将不胜感激。我使用的是 Tomcat 7,下面是目录结构:

Layout of the directories for the client app

谢谢。

更新 - 进一步测试

我将标题缩减为:

<head>
    <title>CometD Tester</title>
    <link rel="stylesheet" type="text/css"href="style/style.css" />
    <script type="text/javascript" src="org/cometd/Cometd.js"></script>
</head>

并从 index.html 中删除了所有 JS。现在包含的唯一 JS 是来自 comet.org 的 Cometd.js。仍然有同样的错误......来自该脚本的第一行:

org.cometd.Cometd = function(name)

不确定我在这里错过了什么。

编辑 - 添加 jquery.cometd-reload.js 这是文件的内容。看起来它是来自 cometd 库的“重新绑定(bind)”功能,而不是使用 jquery(?)。我在 JS 中的速度不够快,无法对此进行调试(我真的是 C++ 开发人员)。

(function($)
{
    function bind(org_cometd, cookie, ReloadExtension, cometd)
    {
        // Remap cometd COOKIE functions to jquery cookie functions
        // Avoid to set to undefined if the jquery cookie plugin is not present
        if (cookie)
        {
            org_cometd.COOKIE.set = cookie;
            org_cometd.COOKIE.get = cookie;
        }

        var result = new ReloadExtension();
        cometd.registerExtension('reload', result);
        return result;
    }

    if (typeof define === 'function' && define.amd)
    {
        define(['org/cometd', 'jquery.cookie', 'org/cometd/ReloadExtension', 'jquery.cometd'], bind);
    }
    else
    {
        bind(org.cometd, $.cookie, org.cometd.ReloadExtension, $.cometd);
    }
})(jQuery);

最佳答案

所以问题是我误解了 Comet.org 网站上的项目布局。我应该按照 cometd primer for non-maven setups 上发布的指示进行操作更紧密。基本上,当您设置项目时,您会下载分发版,然后您需要从 tarball 中捆绑的war 文件 中获取代码。 所以,一旦你提取了 tarball...

  1. cometd-javascript-common-2.5.1.war 中获取 org 文件夹(位于 \cometd-2.5.1\cometd-javascript\jquery\target ) 或 cometd-javascript-jquery-2.5.1.war(位于 \cometd-2.5.1\cometd-javascript\common\target)
  2. cometd-javascript-jquery-2.5.1.war 中获取 jquery 文件夹

org 命名空间定义在文件 org/cometd.js 中,我以前没有,因为我错误地认为它已被 org/cometd/Cometd 替换。 js 文件。命名空间 orgcomet 从该文件的第 17 行开始定义如下:

// Namespaces for the cometd implementation
this.org = this.org || {};
org.cometd = {};

org.cometd.JSON = {};

这些功能现在可以正常工作了。

关于javascript - 简单的 cometd 应用程序 "org is not defined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14605831/

相关文章:

php - 在 PHP 中使用 cometd ?

Tomcat CometProcessor NIO 通过 Apache httpd 提供服务?

asp.net - AJAX Comet - Microsoft 是否正在开发或支持任何解决方案以使其具有可扩展性?

javascript - 检测字段是否使用 JavaScript 或 jQuery 更新

javascript - jQUery/Javascript变量问题

javascript - 打印具有数组的对象的数组索引

javascript - Mongoose 关注者/好友关系查询

javascript - 如何解除绑定(bind)事件

javascript - 如何创建一个由 onclick 触发的简单变量交流发电机?

JavaScript 到 Asp 页面