Jquery Call WebServices

1. Web Service = HelloService.asmx

    <System.Web.Script.Services.ScriptService()>

    Public Class Employee
        Public EmpFirstName As String
        Public EmpLastName As String
    End Class

    <WebMethod()>
    Public Function GetEmployeeDetail() As Object
        Dim objEmp As New Employee()
        objEmp.EmpFirstName = "Tech"
        objEmp.EmpLastName = "Illumination"
        Return objEmp
        'Return "Hello World"
    End Function

2. Page = Default.aspx

    <input type="button" id="btnCallService" value="GetEmployeeDetail" />
    <label id="lblData"></label>

3. JQuery = Default.asxp 

    <script src="Scripts/jquery-3.3.1.js"></script>
    <script type="text/javascript">
        $(function() {
            $('#btnCallService').click(function() {
                $.ajax({
                    type: 'POST',
                    url: 'HelloService.asmx/GetEmployeeDetail',
                    dataType: 'json',
                    contentType: 'application/json; charset=utf-8',
                    success: function(response) {
                        $('#lblData').html(JSON.stringify(response));
                    },
                    error: function(error) {
                        console.log(error);
                    }
                });
            });
        });
    </script>
x

Comments

Popular posts from this blog

การตั้งเวลาระหว่าง Server และ Client

วิธีตั้งค่า NTP บน Primary Domain Controller

Installation and Run Node.JS on IIS