title: Jquery ajax submit data internal server error
body: <p>I'm getting the <code>internal server error:500</code> from <code>webservice</code>. Could you please help me to identify the cause? </p>
  
  <pre><code>$(document).ready(function () {
              $("#btnSubmit").click(InsertRegistration);
          });
  
          function InsertRegistration() {
              var Name = $("#Text1").val;
              var Designation = $("#Text2").val;
              var Address = $("#Text3").val;
  
              $.ajax(
                  {
                      url: "Web/Employee.asmx/StoreEmployee",
                      type: "POST",
                      contenType: "application/json; charset=utf-8"",
                      dataType: "json",
                      data: "{'Name' : '" + Name + "','Designation':'" + Designation + "','Address':'" + Address + "'}",
  
                      success: function (result) {
                          var div = $("#divMessage");
                          div.InnerHtml = result.d;
                          div.html(result.d).fadeIn(1000);
                          setTimeout(function () { div.fadeOut(1000) }, 5000);
  
                      },
                      error: function (xhr, status) {
                          alert("An error occured " + status);
                      }
  
                  }
              );
          }
  </code></pre>
  
  <p>My Web Service is as below i have added script service to the class and [ScriptMethod(ResponseFormat = ResponseFormat.Json)]</p>
  
  <pre><code>[ScriptService]
  [WebService(Namespace = "http://tempuri.org/")]
  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
  // [System.Web.Script.Services.ScriptService]
  public class Employee : System.Web.Services.WebService {
  
      SqlConnection conn = new SqlConnection(
              "Data Source=ADMN-PC;Initial Catalog=demoDb;Integrated Security=true");
  
      public Employee () {
  
          //Uncomment the following line if using designed components 
          //InitializeComponent(); 
      }
      string Name , Designation , Address;
  
      [WebMethod]
      [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
      public string StoreEmployee(string Name, string Designation, string Address)
      {
          this.Name = Name;
          this.Designation = Designation;
          this.Address = Address;
  
          if (InsertEmployeeDB() &gt; 0)
          {
              return "Saved Succesfully";
          }
          else
          {
              return "Error occured while saving...";
          }
  
  
      }
      public int InsertEmployeeDB()
      {
          try
          {
  
              SqlCommand cmd = new SqlCommand("insert into  tblEmp_Personal (Name ,Designation,Address) values ('" + Name + "','" + Designation + "','" + Address + "')",conn);
              conn.Open();
              return cmd.ExecuteNonQuery();
          }
          catch (SqlException ex)
          {
  
          }
  
          return 0;
      }
  
  }
  </code></pre>