jeudi 27 août 2015

How to call a method from controller more once time? AJAX

Sorry if the question is really dumb, however, I couldn't find how to solve it.

I have a very simple methid in a controller:

public string ExactSeconds()
{
   string str = DateTime.Now.Second.ToString();
   return str;            
}

The view is simpler than the method:

<p id="rData"></p> 
<p id="qqqqq">click me!</p> 

JavaScriptCode:

<script type="text/javascript">
  $(document).ready(function () {
    $('#qqqqq').click(function () {
        alert('');
        var url = "/Home/ProverbPartialView";
        $.get(url, null, function (data) {                
            $.get(url, null, function (data) {
                $("#rData").html(data);
            });

        });

    });
 });

However, When I click at id="qqqqq", then it just uploads data(seconds) just for the first time. Then if I click the second time and the next times, then alert('') works perfectly, however it is not called method ExactSeconds, that is I cannot see updated seconds at the view.

How to call method ExactSeconds() always when I click at #qqqqq?

Aucun commentaire:

Enregistrer un commentaire