Monday, August 16, 2010

Making (what it appears to be AJAX Jquery calls while passing in Parameters)

1) Page.aspx


   1:  <html>
   2:  <head runat="server">
   3:  <title></title>
   4:  <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
   5:  <script language="javascript" type="text/javascript">
   6:   
   7:  $(document).ready(function () {
   8:      // Add the page method call as an onclick handler for the div.
   9:      $("#Result").click(function () {
  10:          $.ajax({
  11:          type: "POST",
  12:          url: "JqueryTest01.aspx/GetDate",
  13:          data: "{'name':'Ali'}",
  14:          contentType: "application/json; charset=utf-8",
  15:          dataType: "json",
  16:          success: function (msg) {
  17:              // Replace the div's content with the page method's return.
  18:              $("#Result").text(msg.d);
  19:              }
  20:          });
  21:      });
  22:  });
  23:  </script>
  24:  </head>
  25:      <body>
  26:          <form id="form1" runat="server">
  27:              <div id="Result">Click here for the time.</div>
  28:          </form>
  29:      </body>
  30:  </html>


2) page.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Web.Services;

namespace MyBlog
{
public partial class JqueryTest01 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}


[WebMethod]
public static string GetDate(string name)
{
return name + " - " + DateTime.Now.ToString();
}
}
}






points to take note.
1. scribe fire SUCK when u want to share code!... i need to find a better way!

No comments: