我正在嘗試用signalr做一些事情。 我中心是SignalR不能正常工作
public class Customer : SignalR.Hubs.Hub
{
public void Send(string uid, string from, string msg)
{
string make = from + uid;
Clients.Addmsg(msg, make);
}
}
和客戶端代碼
<script src="Scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
<script src="Scripts/jquery.signalR-0.5.3.min.js" type="text/javascript"></script>
<script src="/signalr/hubs" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
$(function() {
// Proxy created on the fly
var care = $.connection.Customer;
$("#broadcast").click(function() {
// Call the chat method on the server
care.send($('#msg').val(), "HariOm", "jai jai ram")
.done(function() {
console.log('Success!');
})
.fail(function (e) {
console.warn(e);
});
});
// Declare a function on the chat hub so the server can invoke it
care.Addmsg = function (message, make) {
alert(message + msg);
};
// Start the connection
$.connection.hub.start();
});
</script>
我加載頁面
遺漏的類型錯誤後收到此錯誤:無法設置屬性「ADDMSG」的未定義
嘗試使用小寫的集線器名稱:例如'var care = $ .connection.customer;' – nemesv