Calling WebService using jQuery in ASP.Net


Calling WebService using jQuery in ASP.Net

This blog post demonstrates jquery call webservice in web applications. Ajax is an acronym standing for Asynchronous JavaScript and XML and this technology help us to load data from the server without a browser page refresh. You can find the below ajax call example :-
ajax framework, ajax application, ajax jquery, jquery and ajax, ajax code examples, ajax using jquery,
jQuery Ajax
Now you will find the implementation for calling webservice using jqyery ajax with example. and how to make a AJAX call to WebMethod using jQuery ajax. Using jQuery we can call methods or functions defined in server side. Find the below source code :-
jquery call webservice,how to call jquery,jquery call ajax, ajax call using jquery example,how to call ajax in jquery,ajax call jquery example,call function jquery
ajax call jquery example
<html xmlns="">
<head id="Head1" runat="server">
    <script src="scripts/jquery-1.7.2.js"></script>
    <title>How to Call Asp.Net WebMethod using jQuery Ajax in Web Application?</title>
    <script src="jquery-1.7.2.js"></script>
    <script type="text/javascript">
        function ShowCurrentDateTime() {
                type: "POST",                                                   // Request Type
                url: "Default.aspx/GetCurrentDateTime",              // Page URL-> and Method Name
                data: '{name: "' + document.getElementById("txtUserName").value + '" }'

                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: OnSuccess,                                        // Success Method
                failure: function (response) {
        function OnSuccess(response) {
    <form id="form1" runat="server">
        <div><br /><br />
            Your Name:
            <asp:TextBox ID="txtUserName" runat="server" Text="there.."></asp:TextBox>
            <input id="btnGetTime" type="button" value="Show Current Date & Time" onclick="ShowCurrentDateTime()" />&nbsp;&nbsp;   
            <br />
            <br />
            <span id="spnDateTime"></span>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
    // Creating a webmethod to get date and time
    public static string GetCurrentDateTime(string name)
        return "Hey! " + name + Environment.NewLine + "The Current Date & Time is: "
            + DateTime.Now.ToString();
Download Code Snippet

I hope you have enjoyed the development tips of calling webservices using ajax call. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.
Calling WebService using jQuery in ASP.Net Reviewed by Ravi Kumar on 10:17 AM Rating: 5

No comments:

All Rights Reserved by Etechpulse © 2012 - 2017

Contact Form


Email *

Message *

Powered by Blogger.