Update
I realized that this is a caching problem, but I cannot disable the cache. Here is my modified script:
<script src="../../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery.ajaxSetup({
cache: false
});
jQuery("#button1").click(function (e) {
window.setInterval(refreshResult, 3000);
});
function refreshResult()
{
jQuery("#divResult").load("/Home/Refresh");
}
</script>
It updates part of the web page every 3 seconds. It works only once after clearing the web browser cache, after which it does not work - requests are executed in / Home / Refresh without an interval of 3 seconds, data is sent from the server, but nothing is displayed on the web page; subsequent requests send cookie ASP.NET_SessionId = wrkx1avgvzwozcn1frsrb2yh. I am using ASP.NET MVC 2 and C #.
I have a problem with jQuery, this is how my web application works
- The Search.aspx web page containing the form and the jQuery script publish the data for the Search () action in the Home Controller after the user clicks button1.
search.aspx:
<%@ Page Title="" Language="C#"
MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<GLSChecker.Models.WebGLSQuery>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Title
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Search</h2>
<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm()) {%>
<fieldset>
<div class="editor-label">
<%: Html.LabelFor(model => model.Url) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Url,
new { size = "50" } ) %>
<%: Html.ValidationMessageFor(model => model.Url) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Location) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Location,
new { size = "50" } ) %>
<%: Html.ValidationMessageFor(model => model.Location) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.KeywordLines) %>
</div>
<div class="editor-field">
<%: Html.TextAreaFor(model => model.KeywordLines, 10, 60, null)%>
<%: Html.ValidationMessageFor(model => model.KeywordLines)%>
</div>
<p>
<input id ="button1" type="submit" value="Search" />
</p>
</fieldset>
<% } %>
<script src="../../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery("#button1").click(function (e) {
window.setInterval(refreshResult, 5000);
});
function refreshResult()
{
jQuery("#divResult").load("/Home/Refresh");
}
</script>
<div id="divResult">
</div>
</asp:Content>
[HttpPost]
public ActionResult Search(WebGLSQuery queryToCreate)
{
if (!ModelState.IsValid)
return View("Search");
queryToCreate.Remote_Address = HttpContext.Request.ServerVariables["REMOTE_ADDR"];
Session["Result"] = null;
SearchKeywordLines(queryToCreate);
Thread.Sleep(15000);
return View("Search");
}//Search()
1 - script - Search.aspx.
Search() .
, Thread.Sleep(15000); Search().
5 . "" jQuery script
() .
public ActionResult Refresh()
{
ViewData["Result"] = DateTime.Now;
return PartialView();
}
<% @ = "#" Inherits = "System.Web.Mvc.ViewUserControl" % >
<% = ViewData [ "" ]% >
, Internet Explorer 8 /Home/Refresh;
Firefox 3.6.3 /Home/Refresh , - . Firefox , /Home/Refresh 5 .
, , Firefox, script 1, .
.