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 5932011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:46:31+00:00 2026-05-22T14:46:31+00:00

I set up a page method and am trying to call it through jQuery.

  • 0

I set up a page method and am trying to call it through jQuery. Sometimes I get to the success function and sometimes to the error function, seems random to me. In any case, the response contains the entire page mark-up.

I tried using both $.ajax and ScriptManager with same results.
I also tried the idea here: Call ASP.NET PageMethod/WebMethod with jQuery – returns whole page and nothing.

Here is the JavaScript code:

$(document).ready(function() {
    $(".tree").dynatree({
        onActivate: function(node) {
            $('#title').val(node.data.title);
            $.ajax({
                type: "POST",
                url: window.location.href + "/GetData",
                data: "{'ID':22}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(response) { alert(response); },
                error: function() { alert('Error!'); }
            });
        }
    });
});

And here is the c# code:

[WebMethod]
public static string GetData(string ID)
{
    if (string.IsNullOrEmpty(ID))
        throw new Exception("No ID passed!");
    return "Test";
}

Edit: Well I got it working. I changed the parameter type from int to string and now the method is called. I can just do int.Parse later, but why does this even happen?

  • 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-22T14:46:32+00:00Added an answer on May 22, 2026 at 2:46 pm

    What’s happening is that setting data to {} in the jQuery call is the JSON equivalent of setting it to NULL. In that case, there is no webmethod that accepts null and the call fails.

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

Sidebar

Related Questions

I'm trying to write some jquery that will call a function when an object
I am trying to dynamically create COM object, call COM method and set COM
I'm trying to set a page that displays the visitor's IP. All the methods
I have a custom error page set up for my application: <customErrors mode=On defaultRedirect=~/errors/GeneralError.aspx
For while I have been trying to set the Page Scaling of Excel page
I am trying to set up a page that will allow the user to
I am trying to set up a page on a wordpress site that displays
I am trying to setup an ASPX page to call a WCF servcie thorugh
I'm trying to dynamically set the contents of a div on my page and
The error is : Fatal error: Call to undefined method wSpider::fetchPage() Firstly, what I'm

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.