views:

225

answers:

2

simply i'm doing a test i have a div called test and mvc action in the client controler the view

and the controler

    public string testout()
    {
        return DateTime.Now.ToString();
    }

and i'm using jquery to update the div

        $("#B1").live("click", function() {

                $("#test").load("/client/testout");

            return false;
        });

first time a click the bottun i see the date and time in the div test second time i click the botton nothing changed

+2  A: 

Try placing this in your jQuery code before any loads occur:

$.ajaxSettings.cache = false; // or $.ajaxSetup({ cache: false });

This prevents the client from caching the request. If that doesn't work, the problem is the server giving you a cached output.

Nick Craver
thank you thats work great with me $.ajaxSetup({ cache: false });
Khalid Omar
A: 

In ASP.NET MVC it is a good practice for actions to return ActionResult. Try modifying your code like this and see if it makes any difference:

public class ClientController: Controller
{
    public ActionResult TestOut()
    {
        return Content(DateTime.Now.ToString(), "text/plain");
    }
}

and your js:

$(function() {
    $('#B1').live('click', function() {
        $('#test').load('/client/testout');
        return false;
    });
});
Darin Dimitrov
What's the significance of the return false? Does the .live() event bubble in some weird way?
JKirchartz
if `#B1` is an anchor (which we don't know here as the OP didn't show the markup) when you click on it it will simply follow the link and redirect to another page leaving no chance for the AJAX call to execute.
Darin Dimitrov
B1 is a div the code work fine in the first click but the second click i expect the date will be updated nothing happen and the old date still appear in the div b1 and the debuger didn't hit the testout action
Khalid Omar