Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rendering ViewComponent with ajax don't work in Edge/IE11

I have a simple ViewComponent works correctly in the browser chrome and Firefox but do not work in a browser Edge \ IE 11.

The component shows the time (just for example).

Chrome and firefox time is displayed.

Edge Browser \ IE 11, time is displayed only the first time the page is up and remains so, time is "frozen".

but

When I open the browser Edge development tools as well as in IE 11, the component starts to work properly and current time is displayed (just like other browsers)

And when I close the F12 development tools, component stops working (time "frozen").

And it repeated - F12 open the component works, F12 Close component stops working.

Am I missing something here ?

Attaching the simple code of the process Thank you


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

  }

}

Default:

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

});
like image 339
DanielD Avatar asked Nov 09 '22 11:11

DanielD


1 Answers

Try to set cache false in ajaxSetup

$.ajaxSetup({ cache: false });

Or use

$.ajax({ cache: false, //other options... });
like image 83
adem caglin Avatar answered Nov 15 '22 12:11

adem caglin