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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:04:00+00:00 2026-06-04T18:04:00+00:00

I think that it is a very basic question, but I have spent hours

  • 0

I think that it is a very basic question, but I have spent hours looking for an answer with no luck, I’ve the following json object (generated using play!Framework)

{
    "preg.pregunta": [{
        "message":"Debes escribir una pregunta",
        "key":"preg.pregunta",
        "variables":[]
    }],
    "preg":[{
        "message": "validation.object",
        "key":"preg",
        "variables":[]
    }]
}

This is my jquery piece of code

$.ajax({
    type: $target.attr('method'),
    data: dataString,
    url:$target.attr('action'),
    dataType: "json",
    beforeSend: function() {
        //some stuff
    },
    success:function(response){
        //some stuff
    },
    error: function(response){
        //I want to use the json response here.
    }
});

I want to get all inside preg.pregunta (message and key values)

Any help?

UPDATED: well I don’t have enough reputation to answer to myself, this is what I’ve found so far.

Ok maybe it would be more than obvious or I have to study a bit more; I found that jQuery doesn’t parse properly a JSON response if it came along with a HTTP error (400 in this case).

someone knows why this behavior?

I just tested this code in success handler and works perfectly!

$.ajax({
  type: $target.attr('method'),
  data: dataString,
  url:$target.attr('action'),
  dataType: "json",
  beforeSend: function() {
  },
  success:function(response){
    //It is working perfectly!
    $.each(response,function(object){ //first loop of the object
      $.each(response[object],function(values){ //looping inside arrays
        console.log(response[object][values].key) //getting value "key"
        console.log(response[object][values].message) //getting value "message"
      });
    })
  },
  error: function(response){
    //nothing happens here
  }
});

UPDATED 2.

after searching about 2 hours, I’ve found a straightforward solution:

error: function(response){
//Note the jQuery.parseJSON function
var response = jQuery.parseJSON(response.responseText);
  $.each(response,function(object){
    $.each(response[object],function(values){
      console.log(response[object][values].key)
      console.log(response[object][values].message)
    });
  })
}

Explanation: when using error handler, jQuery returns a complex object describing the error, responseText contains the data retrieved from the server, so, you have to parse it using parseJSON function.

Hope this helps!

  • 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-04T18:04:01+00:00Added an answer on June 4, 2026 at 6:04 pm

    Try this:

    error: function(response) {
        var pregunta = response["preg.pregunta"][0].message;
        var key = response["preg.pregunta"][0].key;
    },
    

    If there were multiple values within the preg.pregunta array, you would need to loop and replace the [0] with your iterating variable.

    Also, I don’t quite understand why you’d only want to access the reponse in the error handler only?

    Finally, the code for accessing the JSON is native javascript. This is because when you receive the response it has been converted into a POJS object, no jQuery required.

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

Sidebar

Related Questions

I realize that this is probably a very basic question, but I have spent
here's a very basic question, that I'm sure you will be able to answer
I have a very basic question about ViewPager. I have a ViewPagerActivity that includes
I am trying to write a very thin hypervisor that would have the following
I think this is a very simple question, but I’m new to programming so
I have a very basic regular expression that I just can't figure out why
This is a very basic question, I searched it but i just want to
I know this is a very basic question. But I am really not able
this may well be a very basic question, but I haven't been able to
The question may be very basic but I am not getting clue anyways ...

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.