0

I think the question is trival, however i can not find the solution. Im trying to refresh div automatically, for instance:

<div id="divToRefresh"> @(DateTime.Now)</div>

How can I do this in JQuery?

1

3 Answers 3

3

You cant refresh the div as you suggest. You need to load new content in, for your example this will work

$('#divToRefresh').html(now.format("dd/m/yy h:MM tt"))

The above method uses pure JavaScript. If you want to use .Net you can use JavaScript to launch a AJAX call to a JSON Action Reuslt.

public JsonResult GetDate()
{
    return Json(new { CurDate = DateTime.Now}, JsonRequestBehavior.AllowGet);
}

And your JQuery

$.getJSON('pathToActionResult', function(data) {
    $('#divToRefresh').html(data.CurDate)
});
Sign up to request clarification or add additional context in comments.

Comments

2

Here is a simple pure JavaScript solution to get you started.

http://jsfiddle.net/B7U2d/

Comments

0

for very simple ajax situations like this, I like pjax http://pjax.heroku.com/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.