Calling ASP.Net web service from JQuery

Posted on 2009-02-19
Last Modified: 2012-08-13
I am having major trouble calling web methods from Jquery.

I am not able to call any web methods which exist in the aspx page period. Can't figure this one out.

If i could call a method from a web service, than i could live with that.

Here is where i am at. I am able to call a web method in a web service, however the error callback functions fires instead of the success callback. Ironically it appears that the JSON data is intact in the results. I would have expected that the success method would have fired.

So I will include the code, hope someone out there can help me get this resolved so that i can at least call the web service method and get a successful response.

Thanks in advance.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>

<%@ Register tagprefix="igsch" namespace="Infragistics.WebUI.WebSchedule" Assembly="Infragistics35.WebUI.WebDateChooser.v8.2, Version=8.2.20082.1000, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">

<head id="Head1" runat="server">


    <title runat="server" id="PageTitle">Default</title>

    <link runat="server" id="DynamicLink" rel="stylesheet" type="text/css" href="Content/css/IDE_Dev.css" />

    <link runat="server" id="BaseLink" rel="stylesheet" type="text/css" href="Content/css/Base.css"/>

    <link rel="shortcut icon" href="Content/Graphics/favicon.ico" type="image/x-icon"/>

    <script language="javascript" type="text/javascript" src="Content/ClientScripts/jsLib.js" id="ScriptLib"> </script>     

    <script src="Content/ClientScripts/jquery-1.3.1.min.js" type="text/javascript"></script>

    <script src="Content/ClientScripts/jquery-1.3.1-vsdoc.js" type="text/javascript"></script>


    <script type="text/javascript">


        function PageMethod(pagePath, fn, paramArray, successFn, errorFn) {

            //var pagePath = window.location.pathname;

            //Create list of parameters in the form:


            var paramList = '';

            if (paramArray.length > 0) {

                for (var i = 0; i < paramArray.length; i += 2) {

                    if (paramList.length > 0) paramList += ',';

                    paramList += '"' + paramArray[i] + '":"' + paramArray[i + 1] + '"';



            paramList = '{' + paramList + '}';

            //Call the page method


                type: "POST",

                url: pagePath + "/" + fn,

                contentType: "application/json; charset=utf-8",

                data: paramList,

                dataType: "json",

                success: successFn,

                error: errorFn




        $(document).ready(function() {

            // Add the page method call as an onclick handler for the div.


            $("#btn").click(function() {


            PageMethod("WebService.asmx", "LetsGo", [], AjaxSucceeded, AjaxFailed); //No parameters

            //PageMethod("TestWithParams", ["a", "value", "b", 2], AjaxSucceeded, AjaxFailed); //With parameters






        function AjaxSucceeded(result) {




        function AjaxFailed(result) {









    <form id="form1" runat="server">


    <telerik:RadScriptManager ID="RadScriptManager1" Runat="server">



   <div id="OutPut" style=" border:solid medium Black; border-width:medium;width:100px; height:100px;">




   <input  type="button" id="btn" style="width:50px; height:20px;" />








Imports System.Web

Imports System.Web.Services

Imports System.Web.Services.Protocols

Imports System.Web.Script.Services

Imports System.Web.Script

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.

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

<WebService(Namespace:="")> _

<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _

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

Public Class WebService

    Inherits System.Web.Services.WebService

    <System.Web.Services.WebMethod()> _

     <System.Web.Script.Services.ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _

     Public Function LetsGo() As String

        Return "Hello World"

    End Function



End Class

Open in new window

Question by:talker2004
    LVL 10

    Accepted Solution

    LVL 7

    Author Comment

    There was actually a bug in version 1.3.1 which was causing the problem. You get the points anyway.
    LVL 7

    Author Closing Comment

    there was actually a bug in version 1.3.1, but you get the points anyway.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Title # Comments Views Activity
    HTML table 7 38
    How do I interpret the HTTP accept header? 5 26
    crm written in / c# 1 25
    varchar (max) 5 22
    Hi all! Recently there was EE question and the person wanted to have a multi-column textbox <div> selection, so as a first step to answer I provided a link but that was not complete with JavaScript selection, but had a good style sheet. So as a ques…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now