Search

just show me the code

Tuesday, June 16, 2009

jquery ajax post

....

   93
   94 <div id="Result">Click here for current time</div>

....


   99     <script language="javascript">
  100
  101      //Set up the jQuery Char Counter for text area
  102         $(document).ready(function() {
  104             // Add the page method call as an onclick handler for the div.
  105             $("#Result").click(function() {
  106                 $.ajax({
  107                     type: "POST",
  108                     url: "Main.aspx/GetDate",
  109                     data: "{}",
  110                     contentType: "application/json; charset=utf-8",
  111                     dataType: "json",
  112                     success: function(msg) {
  113                         // Replace the div's content with the page method's return.
  114                         $("#Result").text(msg.d);
  115                     },
  116                     error: function() {
  117                         alert('error');
  118                     } 
  119                 }); 
  120             }); 
  121         });
  122      </script>

Main.aspx.cs ....


   30         [WebMethod]
   31         public static string GetDate()
   32         {
   33             return DateTime.Now.ToString();
   34         }



....

No comments:

Post a Comment

Contributors