【问题标题】:SignalR with DNS带有 DNS 的 SignalR
【发布时间】:2016-04-23 05:21:47
【问题描述】:

我正在我的移动应用程序中创建一个聊天系统,但我遇到了问题。我在我的索引中定义了 jQuery 和 signalR。我还定义了我的服务器的脚本路径。

代码 (index.html)

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">

    <!-- Cordova whitelist plugin -->
    <meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src  'self' 'unsafe-inline' *">

    <!-- Base libs -->
    <script src="libs/ionic/js/ionic.bundle.js"></script>
    <script src="libs/ngCordova/dist/ng-cordova.min.js"></script>
    <script src="cordova.js"></script>

    <!-- Third party libs -->
    <script src='libs/jquery/dist/jquery.min.js'></script>
    <script src='libs/signalR/jquery.signalR.min.js'></script>

    <!-- Location for SignalR lib to open a connection with  -->
    <script src="http://www.mytestserver.nl/chathub/signalr/hubs"></script>  

    <!-- Application Javascript files | put the routing files after the controllers! -->
    <script src="app/app.js"></script>
</head>

我的本​​地主机上有一个工作版本,所以我认为我的代码是正确的。 当我尝试在控制器中使用代码时,出现 404 not found 错误。 我认为这是因为我没有在脚本中定义到服务器的端口。然后 signalR 默认为当前主机(localhost:8100)。

代码 (chatController.js)

.controller('ChatController', ['$scope', '$state', function ($scope, $state) {
       $.connection.hub.url = "http://www.mytestserver.nl/chathub/signalr"; 
       $.connection.hub.start().done(function () {
       console.log("hello world");
    });
}]); 

没有 DNS 进入。我无法定义端口号,因为 DNS 正在删除端口号。定义任何端口号都会导致 404 not found 或 Connection timed out 错误。

我可以做些什么来连接到服务器?

【问题讨论】:

  • jquery 和 angularjs 并不是真正兼容的,我希望你意识到这一点。
  • 最重要的是,您没有在 index.html 中包含 angularjs...
  • @thegio 1) SignalR 是一个基于 jQuery 的库,所以我无法选择。我需要使用 jQuery 进行连接。 2)我正在使用离子。我包含的 Ionic 脚本还包含一个 AngularJS 脚本

标签: javascript jquery angularjs dns signalr


【解决方案1】:

我曾经遇到过这种情况,之前在 devexpress localhost 上运行良好,但是当传输到 IIS 时,路径无法正确映射。

您指定给信号器/集线器的路径可能不正确,因此服务器无法正确拾取它。

尝试像这样将通配符添加到您的信号器/集线器参考中

&lt;script src="~/signalr/hubs"&gt;&lt;/script&gt;

之后打开 javascript 控制台并确保没有错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-02
    • 2012-09-24
    • 2012-04-09
    • 2017-01-27
    • 1970-01-01
    • 2015-04-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多