user1371896
user1371896

Reputation: 2230

getting the ajax output with out parsing

I have a jquery - ajax request running, it provides output in json format. If my guess is correct, The ajax response that we get is parsed one. I would like to get the original raw data i.e. the response without parsing. Is it possible ?

Upvotes: 1

Views: 132

Answers (2)

RemarkLima
RemarkLima

Reputation: 12037

If you're 100% sure you're getting a JavaScript object back (I've always parsed my return from a $.ajax() method), then you'll need to stringify your object.

See: http://www.json.org/js.html

And here: https://github.com/douglascrockford/JSON-js to download the "json.js" file.

With this file you can parse and stringify as needed.

So, to get the text version, you would do:

var sObj = JSON.stringify(j);
console.log(sObj);

However, from what I have read, you will need to parse the return object:

A function to be called if the request succeeds. The function gets passed three arguments: The data returned from the server, formatted according to the dataType parameter;

So it is formatted as a JSON "string", which will still need to be parsed or (quick and dirty) eval'd

Upvotes: 0

Felix Kling
Felix Kling

Reputation: 816442

Remove dataType : "json", or change it to dataType : "text", or simply access the responseText property of the jqXHR object (depending on what you want to do with the data).

For more detailed information, read the documentation: http://api.jquery.com/jQuery.ajax/.

Upvotes: 4

Related Questions