Alex Rivera | Logout

How do I get at the raw JSON response from a jQuery $.getJSON() request?

Asked 2010-10-19T00:31:43.130
9

How do I get at the raw JSON response from a jQuery $.getJSON() request?

I just want to print the raw response in an alert() dialogue in my browser?

Edit
Report

2 Answers

0

http://api.jquery.com/jQuery.getJSON/

I prefer to use the full .ajax methods so I don't have to remember the various signatures of the abstractions.

The docs tell you this is equivalent to getJSON:

$.ajax({
  url: url,
  dataType: 'json',
  data: data,
  success: callback
});

where you could have:

function callback(data) {
    alert(data);
}

I strongly recommend that you use Firefox and Firebug with console.log(); for this kind of thing. Alerts drive you nuts after a while.

Edit

Based on the other responses, I may be misunderstanding your question! You could always use Fiddler to see the raw response.

answered 2010-10-19T00:38:36.063
0

I ended up using the JSON.stringify() feature in https://github.com/douglascrockford/JSON-js/blob/master/json2.js.

Not ideal because it's another javascript file being loaded, but it serves my purpose.

answered 2010-10-19T16:38:32.490

Your Answer