How can I get data from the controller with ajax.
Method in my Controller
public ActionResult StartPage()
{
var result = CommonService.GetCurrentDateTime();
ViewBag.DateAndTimeFromDataBase = result ;
return View();
}
and my Ajax
$(document).ready(function() {
setInterval('getServerDateTime()', 0, 1000);
});
function getServerDateTime() {
$.ajax({
type: 'GET',
cache: false,
url: "/Login/StartPage",
complete: function (req, textStatus) {
var dateString = req.getResponseHeader('Date');
if (dateString.indexOf('GMT') === -1) {
dateString += ' GMT';
}
var date = new Date(dateString);
$('#time-span').text(dateString);
}
});
};
Here I get the date time from the server. And I wanted to take the value of the time date from the controller. And display the difference therebetween. I am new to this. I can’t get the result of that in the controller.
<div>
<span id="time-span" class="date-time"></span>
</div>