use Jquery load to load content in adiv?
I h开发者_如何学Cave a div called test and mvc action in the client controller
The view:
<input id="B1" type="button" value="test" />
<div id="test">
</div>
The controller
public string testout()
{
return DateTime.Now.ToString();
}
I'm using jquery to update the div
$("#B1").live("click", function() {
$("#test").load("/client/testout");
return false;
});
The first time I click the button I see the date and time in the div test. The second time nothing changes.
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.
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;
});
});
精彩评论