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
    });
});

更多相关文章

  1. 浏览器环境下JavaScript脚本加载与执行探析之动态脚本与Ajax脚本
  2. 像C#一样,去写Javascript----记我的脚本库RockSniper.Scripts.js
  3. 包含HTML和JavaScript标记的HTML选择控件作为文本
  4. 如何在详细信息标记的结束事件上添加CSS转换?
  5. 单击内部标记时将类添加到li
  6. 如何为给定的地方放置标记
  7. 使用ng-repeat渲染条件标记
  8. 使用CSS类作为JS标记是一种不好的做法吗?
  9. 在Django模板标记库中导入外部库时出错

随机推荐

  1. Android 告急!
  2. Android学习方向
  3. 安裝 Android 開發工具
  4. flutter与android混合开发一:Android原生
  5. Sony Reader PRS - T1 被駭顯露更多 Andr
  6. Android传感器(第一篇)
  7. 如何上传应用软件到 Android Market集市
  8. 浅谈android应用的版本更新
  9. Android面试系列文章2018之Android部分之
  10. Android中AsyncTask的简单用法及实现网络