【问题标题】:Rendering ViewComponent with ajax don't work in Edge/IE11使用 ajax 渲染 ViewComponent 在 Edge/IE11 中不起作用
【发布时间】:2016-08-01 17:34:34
【问题描述】:

我有一个简单的 ViewComponent 在浏览器 chrome 和 Firefox 中可以正常工作,但在浏览器 Edge\IE 11 中无法正常工作

组件显示时间(仅作为示例)。

显示 Chrome 和 firefox 时间。

Edge Browser \ IE 11,时间仅在页面第一次启动时显示并保持不变,时间被“冻结”。

但是

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

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

它重复了 - F12 打开组件工作,F12 关闭组件停止工作

我在这里遗漏了什么吗?

附上流程的简单代码 谢谢


家庭控制器:

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

获取时间视图组件:

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

});

【问题讨论】:

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


    【解决方案1】:

    尝试在ajaxSetup中设置缓存false

    $.ajaxSetup({ cache: false });
    

    或者使用

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-03
      • 2017-05-27
      • 2017-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-14
      相关资源
      最近更新 更多