[Last Call] Learn how to a build a cloud-first strategyRegister Now


Calling ASP.Net web service from JQuery

Posted on 2009-02-19
Medium Priority
Last Modified: 2012-08-13
I am having major trouble calling asp.net 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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<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:="http://tempuri.org/")> _
<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
  • 2
LVL 10

Accepted Solution

jabcoco earned 2000 total points
ID: 23707638

Author Comment

ID: 23859634
There was actually a bug in version 1.3.1 which was causing the problem. You get the points anyway.

Author Closing Comment

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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…
Suggested Courses
Course of the Month17 days, 17 hours left to enroll

831 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