Error while calling a function using jquery-ajax ("NetworkError: 500 Internal Server Error)
<p>I am trying to call a function from my jquery code but i got stuck at a place where i am getting the error "NetworkError: 500 Internal Server Error.Please help me by making me solve this error also please forgive me if this is a duplicate thread</p>

<p>Here is my jquery code:</p>

<p></p>

<pre><code>$(document).ready(function () {
   // alert("comes here");
    $("#&lt;%=Button1.ClientID%&gt;").click(function () {

        var UserName = $('#&lt;%=TextBox1.ClientID%&gt;').val();
        var Phone = $('#&lt;%=TextBox3.ClientID%&gt;').val();
        var Email = $('#&lt;%=TextBox2.ClientID%&gt;').val();
        var Message = $('#&lt;%=TextBox4.ClientID%&gt;').val();
        alert("comes here 1");
        var json = '{UserName: "' + $("#&lt;%=TextBox1.ClientID%&gt;")[0].value + '",Phone: "' + $("#&lt;%=TextBox3.ClientID%&gt;")[0].value + '",Email: "' + $("#&lt;%=TextBox2.ClientID%&gt;")[0].value + '",Message: "' + $("#&lt;%=TextBox4.ClientID%&gt;")[0].value+'"}';
        //"{'" + UserName + "','" + Phone + "','" + Email + "','" + Message + "'}";
        //var jsonString = JSON.stringify(json);

        alert(json);
        $.ajax({
            type: "POST",
            //C:\Users\hp\Documents\Visual Studio 2010\WebSites\
            //C:/Users/hp/Documents/Visual Studio 2010/WebSites/jQuerySubmitForm/
            url: "Default.aspx/insertdetails",
            data: json,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async: false,
            success: function () { alert("success"); },
            error: OnError,
            failure: function () {
                alert(response);
            }
        });
        function OnError(request, status, error) {
            alert(request.statusText);
            return false;
        }
</code></pre>

<p>and here is my function which i called through jquery code:
[System.Web.Services.WebMethod]
    public static void insertdetails(string name, string emailid, string phone, string message)
    {</p>

<pre><code>    SqlConnection Con = new SqlConnection(@"Server=HP-PC;Integrated Security=True;" + "Database=DB1");
    Console.WriteLine("connected to db");
    string query = "INSERT INTO [SubmissionFormTable]([Name],[Email],[Phone],[Message])" + "VALUES (@Name,@Email,@Phone,@Message)";

    SqlCommand cmd = new SqlCommand(query, Con);
    cmd.Parameters.AddWithValue("@Name", name);
    cmd.Parameters.AddWithValue("@Email", emailid);
    cmd.Parameters.AddWithValue("@Phone", phone);
    cmd.Parameters.AddWithValue("@Message", message);

    try
    {
        Con.Open();

        cmd.ExecuteNonQuery();
    }
    catch (Exception)
    {
        throw;
    }
    finally
    {
        Con.Close();
    }
    //string str_insert = "INSERT INTO remark VALUES(@remark)";

    //SqlParameter[] parameter = {
    //        new SqlParameter("@remark", remark),
    //    };
    // int abc = DBclass.TruyVan_XuLy_VoiThamSo(str_insert, parameter);
}
</code></pre>

<p>}</p>
