Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5974121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:53:53+00:00 2026-05-22T20:53:53+00:00

I’m building an asp.net page that uses a page method call from jquery. This

  • 0

I’m building an asp.net page that uses a page method call from jquery. This is a simple test page but I can’t get it to work and I can’t see why.

I added a script manager to the aspx. Here’s the javascript function:

<script type="text/javascript">

    function CallGetLoaded() {

        var ConfirmLoad = "test string";

        $.ajax({
            type: "POST",
            url: "../Pages/TestPage.aspx/GetLoaded",
            data: ConfirmLoad,
            contentType: "application/text; charset=utf-8",
            dataType: "text",
            success: successLoadLeads,
            error: errorLoadLeads
        });

    };

    function successLoadLeads(thereturn) { alert((thereturn)); };
    function errorLoadLeads() { alert("problem getting return"); };

</script>

And here’s the full code behind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Script.Serialization;
using System.Web.Services;

public partial class Pages_TestPage : System.Web.UI.Page
{

    [WebMethod]
    public static string GetLoaded(string ConfirmLoad)
    {

        string ResultString = "got test";

        return ResultString;
    }
}

Instead of getting back a simple string in the alert popup, I’m sometimes getting back the HTML of the whole page and sometimes the error function; not sure why it varies.
What am I missing?

Thanks for your suggestions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:53:54+00:00Added an answer on May 22, 2026 at 8:53 pm

    I have made some small changes to your code.

    1. Changed your contentType, data and dataType of your $.ajax request
    2. Changed your onsuccess handler to check for .hasOwnProperty("d")
    3. Changed your onerror handler so that you may see what the actual error is.

    I strongly believe that you had a parse error since you used text for parsing and retrieving.

    Here is a sample done from your code that works.

    The MarkUp

    <asp:Button ID="testclick" runat="server" Text="Click Me"/>
    

    The Scripts

    $(function () {
        $('#testclick').click(function (e) {
            CallGetLoaded();
            e.preventDefault();
        });
    });
    
    function CallGetLoaded() {
    
        var ConfirmLoad = "test string";
    
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "TestPage.aspx/Getloaded",
            data: "{'ConfirmLoad':'" + ConfirmLoad + "'}",
            dataType: "json",
            success: function (msg) {
                var data = msg.hasOwnProperty("d") ? msg.d : msg;
                OnSucessCallBack(data);
            },
            error: function (xhr, status, error) {
                alert(xhr.statusText);
            }
        });
    
    };
    
    function OnSucessCallBack(data) {
        alert(data);
    }
    

    The Code-Behind

    [WebMethod]
    public static string GetLoaded(string ConfirmLoad)
    {
        string ResultString = "got test";
        return ResultString;
    }
    

    P.S: As FiveTools have correctly pointed out,

    url:"../Pages/TestPage.aspx/Getloaded" is unnecessary. url:"TestPage.aspx/Getloaded" will do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
We're building an app, our first using Rails 3, and we're having to build
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to loop through a bunch of documents I have to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.