Rendering ViewComponent with ajax not working in Edge / IE11

I have a simple ViewComponent that works correctly in the Chrome and Firefox browser, but does not work in the Edge \ IE 11 browser .

The component shows the time (for example,).

Chrome and Firefox time displays.

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

but

When I open the Edge development tools for the browser, as well as in IE 11, the component starts working correctly and the current time is displayed (like other browsers).

And when I close the F12 development tools, the component stops working (time is β€œfrozen”).

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

Did I miss something?

Attaching a simple process code 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); }); }); 
+5
source share
1 answer

Try setting false cache in ajaxSetup

 $.ajaxSetup({ cache: false }); 

Or use

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

All Articles