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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:16:54+00:00 2026-05-23T13:16:54+00:00

Im ready to start pulling my hair out here. Trying to use jquery ajax

  • 0

Im ready to start pulling my hair out here. Trying to use jquery ajax request in Firefox to return simple string from method in my code behind. Regardless of what I try, I always get parsererror – unexpected character. I tried at least a dozen different variations based on demos Ive found online, none work.

 $.ajax({
                type: 'POST',
                url: '/Search/BasicSearch.aspx/sayHello',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: '{}',
                success: function (msg) {
                    alert(msg.d);
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(textStatus + '  ' + errorThrown);
                }
            });

–code behind method

[WebMethod]
        public static string sayHello()
        {
            return "hello world";
        }

I have tried returning a properly formatted json string in this method, still didnt work.

EDIT: I forgot to mention that this site will is running on .NET 2.0. After unsuccessfully trying Will’s suggestion below to set the response format to JSON, I thought I would try a plain ‘ol generic handler and see what happens. Sure enough, it worked.

public class Handler1 : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
    context.Response.ContentType = "application/json";
    context.Response.Write("{\"\": \"hello world\"}");
}

public bool IsReusable
{
    get
    {
        return false;
    }
}

}

So I am assuming its an underlying issue with .NET 2.0 aspx pages??? I think all of the examples I have seen were using at least 3.0.

  • 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-23T13:16:54+00:00Added an answer on May 23, 2026 at 1:16 pm

    try this it will work .

    As your returned type is not pure json or it is thinking thats why it is failing ,

    remove datatype:json and give a try , it should work

    $.ajax({
                    type: 'POST',
                    url: '/Search/BasicSearch.aspx/sayHello',
                    contentType: "application/json; charset=utf-8",
                    data: '{}',
                    success: function (msg) {
                        alert(msg.d);
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        alert(textStatus + '  ' + errorThrown);
                    }
                });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just starting out with jQuery and want to use $(document).ready() to dynamically generate
Been pulling my hair out over what should have been a quick and easy
Ok, I'm really pulling my hair out on this and have tried a few
Using WAPPS Cmdlets, I'm trying to find out programmatically the moment I can use
I'm getting ready to start a small project that provides an opportunity to use
I've made a simple PHP jQuery Chat Application with Short Polling (AJAX Refresh). Like,
When I start up Eclipse, ready to rock, I have to sit there and
I want to get ready for HTML 5 and start playing around with it.
I have function Start() that is fired on ready. When I click on .ExampleClick
I have the following code: //------------------------------------------------------// // When the document is ready, start firing

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.