title: jQuery $Ajax Post data from webform to code behind method in ASP.NET
body: <p>I am trying to pass data from webform to code behind method and get back value in webform, followed by print it. I have initially test following code to simply post request to method, get string and print in page and it worked, but got issue when trying to post data back to method</p>
  
  <pre><code>$(document).ready(function () {
  
  $(".AddStaffToRoleLink").on("click", function () {
  
             var selectedStaffID = $(this).attr("id");
  
             alert("this is " + selectedStaffID);
  
             $.ajax({
  
                 type: "POST",
                 url: "AddUserInRole.aspx/AddRoleForSelectStaff",
                 contentType: "application/json; charset=utf-8",
                 dataType: "json",
                 data: { selectedStaffID: selectedStaffID },
                 success: function (response) {
                     $("#Content").text(response.d);
                 },
                 failure: function (response) {
                     alert(response.d);
                 }
             });
         });
  
  });
  </code></pre>
  
  <h2>Code behind</h2>
  
  <pre><code>   [WebMethod]
      public static string AddRoleForSelectStaff(string selectedStaffID)
      {
          return "This string is from Code behind  " + selectedStaffID;
      }
  </code></pre>