Calling server side functions using ajax in javascript

In the javascript side

<script>
function insertValue(){
 $.ajax({
                            type: "POST",
                            url: "Default.aspx/serverFunction",
                            data: '{path: "' + path + '"}',
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success: function OnSuccess(){

                            },
                            failure: function (response) {
                                alert(response.d);
                            }


                        });

                 }
                  

 }
</script>

In the code section we use a webmethod to insert value

 [System.Web.Services.WebMethod(EnableSession = true)]
   
        public static string serverFunction(string path)
        {
            SqlConnection con = new SqlConnection(connection.getconnection());
            SqlCommand cmd = new SqlCommand();
           
            cmd.Connection = con;
            cmd.CommandType = CommandType.Text;

           // Your query here


           
            return "";
        }

Comments

Popular posts from this blog

c# console applicaton progress bar with spinner

Paging, sorting and searching in mvc + razor

C# SELF DESTRUCT CONSOLE APP