使信号器生成的代理集线器动态
16lz
2021-01-22
I have a solution which need to connect using CORS to a signalr exposed service. The address where the signalr service will be hosted could change in time, so it's not suitable to have the classic script tag
我有一个解决方案需要使用CORS连接到信号器暴露的服务。寄存信号器服务的地址可能会随时间变化,因此不适合使用经典脚本标记
<script src="http://server:8888/signalr/hubs" type="text/javascript"></script>
but it would be fantastic if there's a way to reference the above url dynamically by javascript without the static script tag. Suggestions would be great!
但如果有一种方法可以通过javascript动态引用上面的url而没有静态脚本标记,那就太棒了。建议会很棒!
3 个解决方案
#1
4
Do the following in your JS file:
在JS文件中执行以下操作:
$.getScript('http://server:8888/signalr/hubs', function () {
//Set the hubs URL for the connection
$.connection.hub.url = 'http://server:8888/signalr';
var hub = $.connection.yourHub; //yourHub is name of hub on the server side
//wire up SignalR
//start hub
$.connection.hub.start().done(function () {
//once we're done with SignalR init we can wire up our other stuff
});
});
更多相关文章
- 浏览器环境下JavaScript脚本加载与执行探析之动态脚本与Ajax脚本
- 像C#一样,去写Javascript----记我的脚本库RockSniper.Scripts.js
- 包含HTML和JavaScript标记的HTML选择控件作为文本
- 如何在详细信息标记的结束事件上添加CSS转换?
- 单击内部标记时将类添加到li
- 如何为给定的地方放置标记
- 使用ng-repeat渲染条件标记
- 使用CSS类作为JS标记是一种不好的做法吗?
- 在Django模板标记库中导入外部库时出错