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

时间:2016-08-01 17:34:34

标签: c# ajax asp.net-core asp.net-core-viewcomponent

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

组件显示时间(例如)。

显示Chrome和Firefox时间。

Edge Browser \ 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}");
}

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

  }

}

默认值:

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

});

1 个答案:

答案 0 :(得分:1)

尝试在false

中设置缓存ajaxSetup
$.ajaxSetup({ cache: false });

或使用

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