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

  • Home
  • SEARCH
  • 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 825175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:12:47+00:00 2026-05-15T03:12:47+00:00

My jQuery ajax call is failing with an undefined error. My js code looks

  • 0

My jQuery ajax call is failing with an undefined error. My js code looks like this:

$.ajax({
   type: "POST",
   url: "Data/RealTime.ashx",
   data: "{}",
   contentType: "application/json; charset=utf-8",
   dataType: "json",
   timeout: 15000,
   dataFilter: function(data, type) {
       alert("RAW DATA: " + data + ", TYPE: "+ type);
       return data;
   },
   error: function(xhr, textStatus, errorThrown) {
       alert("FAIL: " + xhr + " " + textStatus + " " + errorThrown);
   },
   success: function(data) {
       alert("SUCCESS");
   }
});

My ajax source is a generic ASP.NET handler:

[WebService(Namespace = "http://my.website.com")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class RealTime : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "application/json";
        context.Response.Write("{ data: [1,2,3] }");
        context.Response.End();
    }

    public bool IsReusable
    { get { return false; } }
}

Now, if I return an empty object ("{ }") in my handler, the call will succeed. But when I return any other JSON object, the call fails.

The dataFilter handler shows that I am receiving a correct object. Firebug shows the response as expected, and the JSON tab shows that the object is parsed correctly.

So what could be the cause?

[Edit] I should have actually written “when I return any invalid JSON object, the call fails”! 😀

  • 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-15T03:12:48+00:00Added an answer on May 15, 2026 at 3:12 am

    You need valid JSON! 🙂

    Change this line:

    context.Response.Write("{ data: [1,2,3] }");
    

    To this:

    context.Response.Write("{ \"data\": [1,2,3] }");
    

    jQuery 1.4+ doesn’t tolerate invalid JSON like it used to (fails silently/in weird ways), so just add the double quotes and you’re all set. For a handy tool to test JSON validity, checkout JSONLint: http://www.jsonlint.com/

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

Sidebar

Related Questions

I have a jQuery .ajax call: $j.ajax({ type: POST, url: /Services/Cart.asmx/UpdateQuantity, data: data, contentType:
Let's say I have the following jQuery AJAX call: $.ajax({ type: POST, url: MyUrl,
I am doing Ajax call using jQuery and my URL is like http://localhost;3327/DummyAps/Demo.aspx In
Hei guys i have this JQuery Ajax call from my view and it looks
I have this code inside the success function of a jQuery ajax call success:
Heh, I'm using jQuery AJAX Call to pull data from a self hosted webservice
On my website I use a long polling jquery ajax function. This ajax call
Is it possible to use jquery .ajax() call to post a file to the
This works: through jQuery I'm using a jQuery.ajax(..) call to a page e.g. Default.aspx/GetStatus
Is it possible to use a jQuery ajax call to perform Forms Authentication with

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.