2014-11-02 47 views
1

我尝试signalr使用例如在signalR不能连接到远程服务器

[http://www.c-sharpcorner.com/UploadFile/78d182/signalr-sample-chat-application-in-C-Sharp/] 

它的Visual Studio环境中能正常工作在本地主机上。 我将服务器端代码分开并上载到远程服务器上。现在,当我尝试用它抛出这些异常远程服务器连接:

Failed to load resource: the server responded with a status of 404 (Not Found)

Uncaught Type Error: Cannot read property 'client' of undefined connect.js :9

我的代码是在connect.js文件的代码以下块

$(function() { 
    alert('i m here'); 
    $.connection.hub.url = "http://info2gsm.com"; 
    var IWanaChat = $.connection.myChatHub; 
    IWanaChat.client.addMessage = function (message) { 
    $("#listMessages").append('<li>' + message + '</li>'); 

    }; 

    $("#sendMessage").click(function(){ 
    alert($('#txtMessage').val()); 
    IWanaChat.server.send($('#txtMessage').val()); 
    }); 

    $.connection.hub.start(); 

}); 

我的HTML页面是以下块

<html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    <meta name="format-detection" content="telephone=no" /> 
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-   scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" /> 

    <script src="Scripts/jquery-1.8.2.min.js"></script> 
    <script src="Scripts/jquery.signalR-1.0.0.js"></script> 

    <script src="signalr/hubs" type="text/javascript"></script> 
    <script src="Scripts/connect.js"></script> 

     <title>Hello World!</title> 
    </head> 
    <body> 

    <div id="listMessages"> 

     <input type="text" ID="txtMessage"></> 
     <br /> 
     <input id="sendMessage" type="button" value="Send" /><br /> 
    </div> 
     <script type="text/javascript"> 
    </script> 
     <script type="text/javascript" src="cordova.js"></script> 
    </body> 
</html> 

谢谢。

+0

您能够在您尝试打的URL打signalR集线器? – Gjohn 2014-11-03 18:27:01

+0

是的,我可以做到。问题是通过在 2014-11-06 06:33:33

回答

0

好像你的虚拟目录没有拾取signalR集线器。你可以在下面尝试吗?

<script src="/signalr/hubs" type="text/javascript"></script>