Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

json

jquery

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?

like image 841
Kev Avatar asked Oct 19 '10 00:10

Kev


2 Answers

As of jQuery 1.5 the jqXHR object is passed in as the third argument of the callback method. The jqXHR object has a reponseText property that contains the raw JSON string.

function callback(data, status, jqXHR) {
    alert(jqXHR.responseText);
    // or console.log(jqXHR.responseText);
}
like image 67
Mario Menger Avatar answered Oct 24 '22 21:10

Mario Menger


If you're using JSONP, this is fundamentally impossible.

If you're sending a normal request to your domain, replace getJSON with get.

like image 41
SLaks Avatar answered Oct 24 '22 20:10

SLaks