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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:28:33+00:00 2026-06-06T13:28:33+00:00

I’m trying to fetch some JSON data from my server like so: var a

  • 0

I’m trying to fetch some JSON data from my server like so:

var a = $.ajax({
    url: "data.json",
    dataType: 'json',
    data: null,
    error: function(data) {
        console.log("error");
    },
    success: function(data) {
        console.log("success");
    }
});

When I do this, the error function is called (error is printed to the console).

Curiously, though, when I examine a I see that the correct response text has been returned.

a

readyState: 4
responseText: "contents of data.json!"
status: 200
statusText: "OK"

What’s going on? Why isn’t the success callback firing if the request is succeeding?

  • 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-06-06T13:28:34+00:00Added an answer on June 6, 2026 at 1:28 pm

    Probably because the specific value being returned isnt in the type that you specified. The response itself is a success (as you see by viewing the details of “a”), but that is not the only deciding factor for whether succes or error is executed. You specified json as the “dataType” (return type), but received a string. For testing, thats fine, but as you see, things wont run as expected. If you dont specify the dataType option, jQuery will attempt to determine the content type returned by looking at the mime type and the content of the response. Its an error when they dont match up (as in your case).

    UPDATE:

    I realized I rambled in my explanation above. Although you seemed to fix the problem, let me elaborate again.

    There were several possibilities for errors to occur in your situation. The important thing to understand is that if you set “dataType”, jQuery will attempt to parse the responseText with that type. If you do not set that option, it will guess and parse it accordingly (that means it will look at the MIME type) and parse it that way. If you specify the “dataType”, the responseText needs to be in the format of JSON. So if you specify “json”, but provide a string (in your case), jQuery parsing fails. If you don’t specify the “dataType” and jQuery guesses, the responseText needs to match the MIME type. So you can’t return a string when the MIME type is “application/json”. When things don’t match up, that’s when errors occur.

    Hopefully that helps!

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have some data like this: 1 2 3 4 5 9 2 6
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string

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.