javscript delay output

Posted by tazim on Stack Overflow See other posts from Stack Overflow or by tazim
Published on 2010-06-11T04:51:03Z Indexed on 2010/06/11 5:02 UTC
Read the original article Hit count: 371

Filed under:
|

I have written some code to display server's current date and time on browser every time user clicks the button . I have done this using ajax in django with the help of jquery. Now my, problem is I have to continously display the date and time once the button is clicked . Some Sample code or utilities allowing such kind of delay will be helpful . Thanks in advance

The template is :

$(document).ready(function()  
 {  
          $("button").click(function()  
          {  
               $.ajax({  
                   type: "POST",  
                   url :"/showdate/",  
                   datatype: "json ",  
                   success : function(data){  
                             var s = data.currentdate;  
                             var sd = s  
                             $(sd).appendTo("div");  
                            }  
                });  

          });  
 });  

    <button type="button">Click Me</button>
    <div id="someid"></div>

The view function is :

def showdate(request):     
      now = datetime.datetime.now()  
      string_now = str(now)  
      return_dict = {'currentdate':string_now}  
      json = simplejson.dumps(return_dict)  
      return HttpResponse(json,mimetype="application/json")  

© Stack Overflow or respective owner

Related posts about AJAX

Related posts about django