使用ajax渲染ViewComponent在Edge/IE11中不起作用

Dan*_*elD 5 c# ajax asp.net-core asp.net-core-viewcomponent

我有一个简单的ViewComponent在浏览器chrome和Firefox中正常工作不能在浏览器Edge\IE 11中工作.

该组件显示时间(仅举例).

显示Chrome和Firefox时间.

边缘浏览器\ IE 11,时间仅在页面第一次显示时显示并保持不变,时间被"冻结".

当我打开浏览器边缘开发工具以及IE 11时,组件开始正常工作并显示当前时间(就像其他浏览器一样)

当我关闭F12开发工具时,组件停止工作(时间"冻结").

并重复 - F12 打开组件工作,F12 关闭组件停止工作.

我在这里错过了什么吗?

附上过程的简单代码谢谢


HomeController的:

public IActionResult GetTime()
{
   return ViewComponent("GetTime");
   //// var time = DateTime.Now.ToString("h:mm:ss");
  //// return Content($"The current time is {time}");
}
Run Code Online (Sandbox Code Playgroud)

GetTimeViewComponent:

public class GetTimeViewComponent : ViewComponent
{

  public IViewComponentResult Invoke()
  {

   var model = new string[]
   {
     "Hello", DateTime.Now.ToString("h:mm:ss") , "the", "view", "component."
   };
   return View("Default", model);

  }

}
Run Code Online (Sandbox Code Playgroud)

默认:

@model string[]
<ul>
     @foreach (var item in Model)
     {
       <li class="text-danger">@item</li>
      }
</ul>

**Index**

<div id="myComponentContainer">@await Component.InvokeAsync("GetTime") </div>

**Js / Ajax**

$(function () {

   var refreshComponent = function () {
   $.get("Home/GetTime", function (data) {
   $("#myComponentContainer").html(data);
   });
};
   $(function () { window.setInterval(refreshComponent, 1000); });

});
Run Code Online (Sandbox Code Playgroud)

ade*_*lin 1

尝试设置false缓存ajaxSetup

$.ajaxSetup({ cache: false });
Run Code Online (Sandbox Code Playgroud)

或者使用

$.ajax({ cache: false, //other options... });
Run Code Online (Sandbox Code Playgroud)