title: Call server side function using $.ajax
body: <p>Ultimately, I'd like to send a value to the server on a button click and query my DB.  For now, I'm having trouble using jquery.ajax to call a function on the server side.  Here is my code:</p>
  
  <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ajax.aspx.cs" Inherits="WebApplication1.ajax" %&gt;
  &lt;asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server"&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"&gt;
  &lt;script type="text/javascript" src="/Scripts/jquery-1.6.2.min.js"&gt;&lt;/script&gt;
  &lt;script language="Javascript" type="text/javascript"&gt;
      if (jQuery) { alert("jQuery loaded"); }
  
      function send() 
      {
          $.ajax(
              {
                  type: "get",
                  url: "ajax.aspx/Test",
                  data: { name: 'ok' },
                  success: function (result) { alert("successful!"); }
              })
      }
  
    &lt;/script&gt;
    &lt;input type="button" runat="server" value="TryMe" onclick="send()" /&gt;
  &lt;/asp:Content&gt;
  
  [WebMethod]
      [System.Web.Script.Services.ScriptMethod]
      public static string Test(string sendData)
      {
          return String.Format("Hello {0}", sendData);
      }
  </code></pre>