I have an R code that updates the values stored in a text file. I have a controller function which returns a value stored in the text file. How do I repeatedly call the controller function to continuously display the updated values in the view?
Asked
Active
Viewed 507 times
0
-
1You may call you ajax call periodically. Look on [this answer](http://stackoverflow.com/a/5052661/4093924). – vpxfhu77 May 16 '17 at 12:09
-
@SreeLakshmi Agree to Vadim, I think its your best bet. – User3250 May 17 '17 at 04:43
2 Answers
0
If you know before hand the number of times you want to loop you can simply put your ajax call in the javascript for loop and on ajax success keep updating your html view.
If you don't know then you would need implement SingalR or long polling to update your View progressively.
-
And the simplest solution is to use [settimeout](https://www.w3schools.com/jsref/met_win_settimeout.asp) function execute ajax after a specific internal. – mmushtaq May 16 '17 at 12:11
-
You mean to use setInterval function right? I think JS loop is also simple once controller function finishes just exit the loop. Thoughts? – User3250 May 16 '17 at 12:33
-
But it think it will conflict with asynchronous behavior of ajax call. – mmushtaq May 16 '17 at 12:51
-
Okay. Coz I wanted to use same kind of same methodology for ajax calls. I will try with synchronous ajax calls and see how it works – User3250 May 16 '17 at 12:55
-
Can you please help me out with a simple example on how to put ajax call in javascript for loop? – Sree Lakshmi May 17 '17 at 04:33
0
Ajax Function:
function CallPageMethod(Url, ReqType, ContentType, CacheFlag, DataArray, SuccessMethod, FailureMethod) {
$.ajax({
url: Url,
type: ReqType,
contentType: ContentType,
cache: CacheFlag,
data: DataArray,
success: function (resData) { return window[SuccessMethod](resData); },
error: function (error) { return window[FailureMethod](error); }
});
}
Call Ajax function:
function GetDetails() {
var serviceUrl = "/[Controller]/[ActionMethod]";
var array = {};
CallPageMethod(serviceUrl, PostReq, CTDefault, false, array, "Success", "Fail");
}
function Success(resData) {
}
function Fail(errData) {
}

Prabhat Sinha
- 1,500
- 20
- 32