我想使用SignalR与跨域,但我在调用启动函数时收到错误消息。错误消息是"Uncaught TypeError: Cannot call method 'start' of undefined "
使用SignalR与跨域
我使用的代码 服务器端:
[装配:OwinStartup(typeof运算(SignalRChat.Startup))]
namespace SignalRChat
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.Map("/signalr", map =>
{
map.UseCors(CorsOptions.AllowAll);
var hubConfiguration = new HubConfiguration
{
EnableJSONP = true
};
map.RunSignalR(hubConfiguration);
});
}
}
}
Client side code.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="/Scripts/jquery-1.6.4.min.js"></script>
<script src="/Scripts/jquery.signalR-1.1.4.min.js"></script>
</head>
<body>
<div></div>
<script type="text/javascript">
var connection = $.connection.hub.url ='http://localhost:9370/signalr';
connection.hub.start()
.done(function() {
alert('Now connected, connection ID=' + connection.id);
});
</script>
</body>
</html>
请您可以添加的JavaScript,尤其在你的集线器/连接上调用start()? – penderi