javascript - SignalR 2.0 - Accessing hub without proxy -
with following html/js code able call signalr 2.0 hub if html/js , hub resides on same server.
<!doctype html> <html> <head> <title>test signalr 2.0</title> <style type="text/css"> .container { background-color: #99ccff; border: thick solid #808080; padding: 20px; margin: 20px; } </style> </head> <body> <div class="container"> <input type="text" size=100 id="message" /> <input type="button" id="sendmessage" value="send" /> </div> <ul id="discussion"></ul> <!--script references. --> <script src="scripts/jquery-1.6.4.min.js"></script> <script src="scripts/jquery.signalr-2.0.3.min.js"></script> <script src="/signalr/hubs"></script> <script type="text/javascript"> $(function () { //instanciating hub-class var srv = $.connection.pvhub; // definition of function called hub (server) srv.client.receivedata = function (message) { var encodedmsg = $('<div />').text(message).html(); $('#discussion').append('<ul>' + encodedmsg + '</ul><br>'); }; // start connection. $.connection.hub.start().done(function () { $('#sendmessage').click(function () { // call hub function (on server) srv.server.getbnodata($('#message').val()); // clear text box , reset focus next comment. $('#message').val('').focus(); }); }); }); </script>
now trying call hub same html/js file located on client. no success. think, there issues hub proxy , url of hub on instantiating connection , start it. strictly speaking no idea how resolve this.
any idea?
thx.
you need enable cross domain support. read this:
http://www.asp.net/signalr/overview/signalr-20/hubs-api/hubs-api-guide-javascript-client#crossdomain
also, in case have set up, have update client code point @ right endpoint, updating /signalr/hubs
relative address absolute one, , specifying valid absolute address $.connection.hub.url
. like:
<script src="http://foo.com/signalr/hubs"></script> <script> ... $.connection.hub.url = 'http://foo.com/signalr'; ... </script>
Comments
Post a Comment