Home > Net >  Best way to update view content without page reload
Best way to update view content without page reload

Time:08-09

Good afternoon! Dear .net developers. Please tell me, I want to develop an .net core MVC page in which the current exchange rates will be displayed. I will receive exchange rates from the database, it will be EntityFramework or Dapper. In this database, another system saves current rates. I plan to make a call to the database in the controller method, get the current exchange rates, collect them in the viewModel and pass it to the view, then display these rates in a tabular form to the user. Since exchange rates can change frequently, I need to always update the content in the view, is there a better way to update the content of the view, like once every 5 or 10 seconds without reloading the page? At the moment, only AJAX queries come to my mind, I very rarely have to develop applications with a user interface, so I may not know many interesting things. Please share your experience, I will be glad to any of your ideas and suggestions. I would like to note that this page will not contain any buttons, in other words, it is necessary to start the process of the scheduled update immediately after the user has opened the page in the browser. And one more question, if these are still AJAX requests, how correct will it be to use the SetInterval function that will launch AJAX at the specified interval? Since I am very concerned about performance and resource management :) I apologize in advance for any errors in the text.

CodePudding user response:

as you said "ajax" is the way to do it.

You can use the built-in javascript "setInterval"

var ajax_call = function() {
  //your jQuery ajax code
};

var interval = 1000 * 60 * X; // where X is your every X minutes

setInterval(ajax_call, interval);

or

setInterval(function() {
  //your jQuery ajax code
}, 1000 * 60 * X); // where X is your every X minutes

this helps to refresh page on given interval of time I never Used but I have seen this code on projects I have been worked on.

SetInterval will be best way to do it .

  • Related