I need to refresh a textarea element every few seconds. My solution involves calling the refresh method inside the controller inside the $("#element").ready with jquery ajax. I would expect that after the call has been made, the ready event would be refired, which unfortunately does not happen. Here is my javascript code :
$("#logTextArea").ready(function () {
alert("ready!");
setTimeout(reloadLogBox(), 5000);
});
function reloadLogBox() {
$.ajax({
url: '/json/AdminsStartUpdate/RefreshLogBox',
type: "Post",
success: function (response) {
alert(response);
$("#logTextArea").html = response;
}
});
}
and controller method (C# code) :
[HttpPost]
public JsonResult RefreshLogBox()
{//breakpoint here
//TODO : get log file contents
string logContents = "Lorem ipsum dolor sit amet " + DateTime.Now.ToString("hh:mm:ss");
return new JsonResult { Data = logContents };
}
How can this be done correctly? I seached the internet a bit and found the on solution here Refire ready event after AJAX reload and in several other similar links, but I'm not certain on how to implement it in my particular case. Thanks!