gpt4 book ai didi

asp.net-mvc - IE 11 + SignalR 不工作

转载 作者:行者123 更新时间:2023-12-01 23:30:54 27 4
gpt4 key购买 nike

在 IE 11 中使用 signalR 时会发生奇怪的行为。场景:

我们有一些调度程序类型的功能,其中调度程序执行一些操作,而其他用户可以实时查看更新(查询)。发送的参数顺利通过并导致 IE 客户端更新,而无需打开开发者控制台。

但是有一种方法不起作用(performUpdate - 获取查询结果 - 这是服务器 > 客户端调用,而不是客户端 > 服务器 > 客户端) - 永远不会被调用。仅当开发者控制台打开时才会调用它。

这是我尝试过的:

Why JavaScript only works after opening developer tools in IE once?

SignalR : Under IE9, messages can't be received by client until I hit F12 !!!!

SignalR client doesn't work inside AngularJs controller

一些代码片段

调度员端

在下拉列表更改时,我们获取当前选定的值并通过网络发送更新。 (这很好用)。

$('#Selector').on('change', function(){
var variable = $('#SomeField').val();
...
liveBatchHub.server.updateParameters(variable, ....);
});

服务器端

当调度程序搜索时,我们有一些服务器端代码发送搜索已运行的通知,并告诉客户端提取结果。

public void Update(string userId, Guid bId)
{
var context = GlobalHost.ConnectionManager.GetHubContext<LiveBatchViewHub>();
context.Clients.User(userId).performUpdate(bId);
}

客户端(实时更新的查看器)

除非开发人员工具打开,否则永远不会调用此函数

liveBatchHub.client.performUpdate = function (id) {
//perform update here
update(id);
};

编辑

更多可能有用的信息(我不确定为什么它会产生影响),但这似乎只在我进行服务器>客户端调用时才会发生。当调度程序更改搜索参数时,更新为客户端>服务器>客户端或调度程序客户端>服务器>查看器客户端,这似乎有效。单击搜索后,搜索管道中的服务将调用 performUpdate 服务器端(服务器 > 查看器客户端)。不确定这是否重要?

编辑 2 和最终解决方案

眼睛布满血丝,我意识到我遗漏了这个问题的一个关键部分:我们也在这个页面上使用角度。我想我已经盯着它看太久了,把它遗漏了——抱歉。我给了 JDupont 答案,因为他走在正确的道路上:缓存。但不是 jQuery 的 ajax 缓存,而是 Angulars $http。

为了避免其他人花费几天/几夜的时间用头撞 table ,最终的解决方案是使用 Angulars $http 禁用 ajax 调用的缓存。

取自 here :

myModule.config(['$httpProvider', function($httpProvider) {
//initialize get if not there
if (!$httpProvider.defaults.headers.get) {
$httpProvider.defaults.headers.get = {};
}

// Answer edited to include suggestions from comments
// because previous version of code introduced browser-related errors

//disable IE ajax request caching
$httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT';
// extra
$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
$httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
}]);

最佳答案

我过去在 IE 中也经历过类似的行为。我可能知道解决您问题的方法。

IE默认缓存一些ajax请求。您可能想尝试全局关闭此功能。看看这个:How to prevent IE from caching Ajax with jQuery

基本上,您可以像这样全局关闭此功能:

$.ajaxSetup({ cache: false });

或者对于像这样的特定ajax请求:

$.ajax({
cache: false,
//other options...
});

我的 GET 请求缓存也有类似的问题。除非开发工具打开,否则我的更新功能只会启动一次。当它打开时,不会发生缓存。

关于asp.net-mvc - IE 11 + SignalR 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31251720/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com