I'm using ajax to check whether there is no new alerts stored in my sql database. I've set it to run every 30 seconds but instead it keeps on calling the function that checks the database every second. Here is my code.
This is code in the view. "_Tasks" is my partial view and it will be the view that is going to be updated. I haven't done anything for a success return because it never reaches that code.
@Html.Action("_Tasks") <script type="text/javascript"> (function poll() { $.ajax({ type: 'GET', cache: false, url: '@Url.Action("TasksRefresh")', dataType: "json", complete: poll, timeout: 30000, success: function (data) { if (data.success == true) alert("Hello"); } }); })(); </script> This is in the controller
public JsonResult TasksRefresh() { var alerts = getAlerts(); var cache = HttpRuntime.Cache["Tasks"]; if ( cache == alerts) { return Json(new { success = false, }); } else { return Json(new { success = true, // View = this.Re }); } }