Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Signalr 访问控制允许原点不允许信号机_Signalr - Fatal编程技术网

Signalr 访问控制允许原点不允许信号机

Signalr 访问控制允许原点不允许信号机,signalr,Signalr,我发现了错误 XMLHttpRequest cannot load http://127.0.0.1:8099//negotiate?_=1348566460118. Origin http://localhost:49848 is not allowed by Access-Control-Allow-Origin 如果我运行下面的代码 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> &l

我发现了错误

XMLHttpRequest cannot load http://127.0.0.1:8099//negotiate?_=1348566460118. Origin http://localhost:49848 is not allowed by Access-Control-Allow-Origin
如果我运行下面的代码

    <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>

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

</head>
<body>
    <script type="text/javascript"> 
        jQuery.support.cors = true;
        var con = $.connection("http://127.0.0.1:8099/");
        $.connection.url = "http://127.0.0.1:8099/signalr";

        con.start({ transport: 'auto', xdomain: true }, function () {
           console.log('connection started!');
       });




    </script>

</body>
</html>

jQuery.support.cors=true;
var con=$.connection(“http://127.0.0.1:8099/");
$.connection.url=”http://127.0.0.1:8099/signalr";
con.start({transport:'auto',xdomain:true},函数(){
log('连接已启动!');
});

该代码有两个问题:

1) 您缺少对/signalr/hubs的脚本引用

在您的情况下,它必须来自自托管服务器。因此,您需要添加:

<script src="http://127.0.0.1:8099/signalr/hubs"></script>
应该是

jQuery.support.cors = true;

var con = $.connection.hub;
con.url = "http://127.0.0.1:8099/signalr";

con.start(function() {
    console.log('connection started!');
});
jQuery.support.cors = true;

var con = $.connection.hub;
con.url = "http://127.0.0.1:8099/signalr";

con.start(function() {
    console.log('connection started!');
});