Click here to Skip to main content
15,882,412 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Good day, I would like to find out how to refresh data in a MVC program, it must be an asynchronous request and you must also utilize Jquery. TIA

What I have tried:

Creating a partial view

<div id="refreshme">
    @Html.Partial("_Stats", Model.Stats)
</div>


function refresh() {
    $.get('/index/post', function(result) {
        $('#refreshme').html(result);
    });
}
setInterval(refresh, 3000);
Posted
Updated 25-Nov-20 9:52am
Comments
Richard Deeming 25-Nov-20 6:21am    
What's wrong with the code you've posted?

I'd also question why you need to use jQuery when modern browsers all support the Fetch API:
Using Fetch - Web APIs | MDN[^]
Member 14797054 25-Nov-20 6:36am    
Good day, my instructions force me to use Jquery to make the async request. So I am trying to find as many solutions as possible to learn from.
Richard Deeming 26-Nov-20 4:58am    
At the risk of repeating myself: what's wrong with the code you've posted?

1 solution

Really hard to pinpoint what could be the problem without looking into your full code, but I hope you can get something from this article: ASP.NET MVC 5: Implementing a ShoutBox Feature Using jQuery and AJAX[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900