Friday, September 9, 2016

Implement Jquery Ajax call learning


Hey wassup, below is the sample code to understand the JQuery Ajax call.


IN DESIGN page in header part implement below code:

<script type="text/javascript">
     
        function btnSort_Click() {
            debugger;
            var pageurl = "Default.aspx/BubbleSort";
            var inputarray = { "inputarray": $('#usrnm').val() };
            alert(inputarray);
            $.ajax({
                type: 'POST',
                url: pageurl,
                data: JSON.stringify(inputarray),
                contentType: 'application/json; charset=utf-5',
                dataType: 'json',
                success: function (data) {
                    alert(data.d);
                },
                error: function (data, success, error) {
                    alert("Error: " + error);
                }
            });
            return false;

        }
    </script>


DESIGN Page in Body part
<input type="button" onclick="btnSort_Click()" value ="Sort"/>




IN CODE BEHIND implement your below code:

[WebMethod]
        public static string BubbleSort(string inputarray)
        {
         
            int[] input = inputarray.Split(',').Select(int.Parse).ToArray();

            return inputarray;
        }

No comments:

Post a Comment