Timed Ajax Calls With JQuery And ASP.NET

 
 
We want to periodically call our "timeserver" using Ajax calls and here's the ASPX and JavaScript needed
 
 
  1. <head runat="server">

  2.     <title>Untitled Page</title>

  3. </head>

  4. <script src="jquery.js" type="text/javascript"></script>

  5. <script type="text/javascript">

  6. $(document).ready(function() {

  7.      setTimeout(MyUpdate,10 * 1000);

  8. });

  9.  

  10.  

  11.    

  12. function MyUpdate()

  13. {

  14.     $.get("ajaxdata.ashx",function(result)

  15.         {

  16.             if ( $('#lblMinute').text() != result )

  17.             {

  18.                 $('#lblMinute').html(result);

  19.                 $('#lblMinute').fadeOut(450);

  20.                 $('#lblMinute').fadeIn(450);

  21.                 $('#lblMinute').fadeOut(450);

  22.                 $('#lblMinute').fadeIn(450);

  23.                 $('#lblMinute').fadeOut(450);

  24.                 $('#lblMinute').fadeIn(450);

  25.             }

  26.         });

  27.     setTimeout(MyUpdate,10 * 1000);

  28.  }

  29. </script>

  30. <body>

  31.     <form id="form1" runat="server">

  32.     <div>

  33.     <span style="background-color:LightBlue" >Autoupdating every 10 seconds...</span>

  34.     <table border="1">

  35.     <tr>

  36.     <td>Something</td>

  37.     <td><asp:Label ID="lblDataUpdated" runat="server">Hello there bla bla</asp:Label></td>

  38.     </tr>

  39.     <tr>

  40.     <td>Other important stuff</td>

  41.     <td>Again more bla bla</td>

  42.     </tr>

  43.     <tr>

  44.     <td>Current minute is</td>

  45.     <td><asp:Label ID="lblMinute" runat="server"></asp:Label></td>

  46.     </tr>

  47.  
 
Copy to Clipboard      Download code as Text Format
 
  Date entered : 20th Apr 2007
  Rating : No Rating
  Accessed  :  1930
  Submitted by :  ahmedraza
 
   Add Comment  Printer friendly
   View All Comments  Email to a friend
   Add to my Favourites Download PDF version
   Rating  
 
                 Click each image to add
this page to each site.
 
 
 
Comments Available

    No comment available at the moment.Be the first one to make a comment

 
Related ASP.NET Source Codes
  • Spring
  • Wraps a string to a given number of characters using a string break character
  • Uppercase the first character of each word in a string
  • Make a string's first character uppercase
  • Strip whitespace (or other characters) from the beginning and end of a string

  • Copyright © 2010 VisualBuilder. All rights reserved