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?
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?
If you're using JSONP, this is fundamentally impossible.
If you're sending a normal request to your domain, replace getJSON
with get
.
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.
I ended up using the JSON.stringify()
feature in http://www.json.org/json2.js.
Not ideal because it's another javascript file being loaded, but it serves my purpose.