Development Experience

Thursday, April 2, 2015

Asp.net ajax Post example

To ajax post your backend method you can use the following snippet
I assume that your page name is : ConfirmWaitingOperations.aspx
Your backend method is : DeclineOperationWeb
Code Behind :
[System.Web.Services.WebMethod()]
        public static void DeclineOperationWeb(object ConfirmId , object Result)
        {
        ...
        }
ASPX Part:
//In your JS function you can use the following ajax post code
        $.ajax({
                type: "POST",
                url: "ConfirmWaitingOperations.aspx/DeclineOperationWeb",
                data: "{ConfirmId:" + id + ",Result:'"+summary+"'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                   alert("Your error here")
                   location.reload(); //refresh page may be 
                },
                error: function(xhr, textStatus, error){
                    alert("Your error here")
                    
                }
            });

No comments:

Post a Comment