Call Web Service Using Jquery Ajax in JavaScript in Asp.Net C#

Call Web Service Using Jquery Ajax 

Web Service Form Addition Function Create Public and Call The One Form Using in JQuery Ajax Display Result  Particular Function  Calling Form Using Asp.Net C#.

                         Download Coding


                       HTML CODING

<html xmlns="">
<title>Run JavaScript function at specific intervals of time</title>
 <script src="jquery.js" type="text/javascript"></script>
    <script type="text/javascript">
        function CallAddition() {
                type: "POST",
                url: "WebService.asmx/Addition",
                data: "{ 'number1': " + $("#txtNumber1").val() + ", 'number2': " + $("#txtNumber2").val() + "}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: OnSuccess,
                error: OnError

        function OnSuccess(data) {

        function OnError(request, error) { 
            $("#lblResults").html("Invalid Input");
        function ClearTextBoxes() {
            document.getElementById('txtNumber1').value = '';
            document.getElementById('txtNumber2').value = '';

    <form id="form1" runat="server">
      <div align="center">     
                            <asp:Label ID="Label1" runat="server" Text="Number1"></asp:Label>
                            <asp:TextBox ID="txtNumber1" runat="server" />
                            <asp:Label ID="Label2" runat="server" Text="Number2"></asp:Label>
                            <asp:TextBox ID="txtNumber2" runat="server" />
                        <asp:Label ID="Label3" runat="server" Text="Result"></asp:Label>
                            <asp:Label ID="lblResults" runat="server" Font-Size="Large" ForeColor="#CC3300"></asp:Label>
                    <tr><td colspan="2>
                        <asp:Button ID="Button1" runat="server" OnClientClick="CallAddition(); return false;" Text="Add" />
                        <asp:Button ID="Button2" OnClientClick="ClearTextBoxes();" runat="server" Text="Reset" />
           C# CODING(WebService.asmx)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
public class WebService : System.Web.Services.WebService {

    public WebService () {

        //Uncomment the following line if using designed components

    public int Addition(int number1,int number2)
        return number1+number2;

First - Add New - WebService.asmx Form 

Next - Create Add Program - Public 

Next - Add - New WebForm - Select TextBox & Label From ToolBox

Next - Script File Add - JQuery Plugin - Call The WebService Form  - Assign  Result For Label

Next - Call Function  To Button 


Post a Comment