开发者

JQuery.load() return only first answer fresh and after only same old data

I use function JQuery.load().

On first call, there is return correct partial view.

I expected that if I click on check box again and again, on each click in td "example" refresh actual time.

Problem is that function return correct time only on first call. On next call, it returns same value (in this moment old time).

In debug, break-point in controller catch only first call. Other calls ignore.

It seems that ASP generate partial view just once and return it again and again.

What I can do if i need on each call fresh data?

For this example exist solution without ajax, but i need it for more complex problem.

java:

<script type="text/javascript">
function Example() {
    jQuery('#example').load('/Home/Example/1/1'); 
}
</script>

View:

...
<table>
    <tr>
        <td>
            <% Html.RenderPartial("Example"); %>
        </td>
        <td id="example">xxx
        </td>
    </tr>
</table>
<input class="checkbox" type="checkbox" name="xxx" id="xxx" 
       开发者_Python百科                         onclick="Example();" />
...

Partial View "Example.ascx":

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<%@ Import Namespace="System" %>

<%= DateTime.Now.ToLongTimeString() %>

Controller:

public ActionResult Example(string locality, int id)
{
    return PartialView("Example");
}

PS: If i call it by HTML.RenderPartial, it is fresh on each refresh, but call by ajax is fresh only on first call on compile. After resresh it returns still old data.


Stop jQuery .load response from being cached

You need .ajax :)


You could use $.ajax and set cache: false

Like this:

    $.ajax({
        url: '<%: Url.Action("Requests", "Home", new{ area = "Competition"})%>',
        cache: false,
        type: "GET",
        dataType: "html",
        success: function (result) {
            $("#divCompetitionRequests").html(result);
        }
    });

and there is a nice solution @ayk answer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜