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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:07:40+00:00 2026-05-23T08:07:40+00:00

The following function results in the response variable being null in Chrome and Safari

  • 0

The following function results in the response variable being null in Chrome and Safari but not Firefox.

function updatePage(response){ // This argument differs by browser

    response = jQuery.parseJSON(response);

    for(var i=0; i<response.length; i++){
        // conduct magic
    };

};

Error:

Uncaught TypeError: Cannot read property 'length' of null

This is because feeding jQuery.parseJSON() anything but a JSON string returns null. It seems Chrome and Safari automatically parse JSON without explicitly being requested. If I test the “response” argument before trying to parse it with jQuery, it’s already a JSON object in both Chrome and Safari. However, in Firefox it’s still a string.

The only solution I’ve come up with to handle this across browsers is to determine if “response” has already been parsed by checking its constructor:

function updatePage(response){

    if(response.constructor === String){
        response = jQuery.parseJSON(response);
    };

    for(var i=0; i<response.length; i++){
        // conduct magic
    };

};

Am I missing something or is this the only way to handle this currently? Seems like jQuery.parseJSON would detect the user-agent and just return the argument as-is in the case of Chrome/Safari.

Pertinent information

  • This is jQuery 1.6.1
  • The response Content-Type from the server is application/json
  • The response argument is originating from your standard jQuery AJAX call:

$.ajax({
    url: API_URL + queryString + '&limit=' + limit,
    type: 'GET',
    cache: false,
    context: document.body,
    success: updatePage,
    error: function(err){
        console.log('ERROR: ' + err);
    }
});
  • 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-23T08:07:41+00:00Added an answer on May 23, 2026 at 8:07 am

    It’s not Chrome or Safari, it’s jQuery that does the parsing if it sees the appropriate Content-Type on the response. (Update: And the Content-Type you’ve added to the question is correct.) I can’t immediately see why it wouldn’t be doing it on Firefox.

    You can force it to always do the parsing by adding dataType: 'json' to your call, details in the jQuery.ajax docs. Then you wouldn’t call parseJSON at all, response would already be the deserialized object.

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

Sidebar

Related Questions

I use the following jquery statements but i get error in this function onGetDataSuccess(result)
I'm using the following in the web page but can't get a response from
I have the following code: var acOptions = { source:function (request, response) { $.ajax({
The following autocomplete code works with Jquery 1.4.4 but not with 1.5.1. I am
I have the following php code (getRout.php).. which response results in xml formats ...
I have the following function: - (NSString *)urlEncodedValue { NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(
Ok, I have the following function: function TfPackagedItemEdit.GetRTFDescription: TStringList; begin Result.Text := richDescription.Lines.Text; //stringlist
Inside my template function I have the following code: TypeName myFunction() { TypeName result;
The following function System.Threading.Thread.Sleep(); delay the thread in millisecond, and take the integer value
/** The following function checks the red black tree black height * @param n

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.