title: Invoke Server Methods From Client Side Using jQuery AJAX in ASP.NET
body: <p>I have to call server side method update(input parameters) by using ajax call.when I am running the code my ajax is not loading.I want to update that data to Jquery Data table.please give me suggestions </p>
  
  <p>$(document).on('click', '#btnsave', function () {</p>
  
  <pre><code>                        //have to get the emp_id
                          var id = $('#hdnid').val();
                          update(id);
  
                      });
  </code></pre>
  
  <p>function update(id) {</p>
  
  <pre><code>            var name = $('#txtempname').val();
  
              var sal = $('#txtsal').val();
  
              var Dept_Id = $('#ddllist').val();
  
              $.ajax({
                  //var Data = "{ empname:" + name + "}";
  
                  url: 'jdatatable.aspx/update',//my  .aspx page name 
  
                  type: "POST",
  
                  data: '{ id: ' + id + ',empname: "' + name + '", sal: ' +sal + ', Dept_Id: ' + Dept_Id + ' }',
                  contentType: "application/json; charset=utf-8",
  
                  dataType: "json",
  
                  "success": function (data) {
  
                      alert("successfully done");
  
                      table.ajax.reload();
  
                      $('#txtempname').val('');
  
                      $('#txtsal').val('');
  
                      $('#ddllist').val('');
  
                  },
                  "error": function (data, xhr, status) {
                      alert(status);
                  }
              });
  </code></pre>
  
  <p>jdatatable.aspx.cs</p>
  
  <p>protected void Page_Load(object sender, EventArgs e)
          {</p>
  
  <pre><code>        if (!Page.IsPostBack)
          {
  
  
  
  
          }
  
  
      }
  </code></pre>
  
  <p>//mymethod
   [System.Web.Services.WebMethod]</p>
  
  <p>[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json, XmlSerializeString = false)]</p>
  
  <pre><code>    public void update(int id, string empname, int sal, int Dept_Id)
      {
  
          string s =    ConfigurationManager.ConnectionStrings["dbconn"].ToString();
          List&lt;UserDetails&gt; li = new List&lt;UserDetails&gt;();
          SqlConnection con = new SqlConnection(s);
          con.Open();
          SqlCommand cmd = new SqlCommand("sp_update", con);
          cmd.CommandType = CommandType.StoredProcedure;
          cmd.Parameters.Add(new SqlParameter("@id", id));
          cmd.Parameters.Add(new SqlParameter("@Emp_Name", empname));
          cmd.Parameters.Add(new SqlParameter("@Sal", sal));
          cmd.Parameters.Add(new SqlParameter("@Dept_Id", Dept_Id));
          cmd.ExecuteNonQuery();
          con.Close();
      }
  </code></pre>