kevinius
kevinius

Reputation: 4610

jquery $.get() doesn't return a string but an object

I'm working on an app that gets an xml file, wraps it to a json object and runs it trough a handlebars templates.

I'm using the jquery $.get() function to get the data from an xml file. However, i get an object (Document) returned, and i need the contents of my xml file as a string.

$.get(appCore.location, function (data){return data //but it's an object}

If you need more code, give a shout, but i'm not doing anything more than a simple $.get().

thx,

Upvotes: 0

Views: 77

Answers (2)

user1655489
user1655489

Reputation: 36

Set the Content-type header of the response to text-plain.

Upvotes: 0

Andy
Andy

Reputation: 14575

You don't always get a string from $.get(), read here:

returned data, which will be an XML root element, text string, JavaScript file, or JSON object, depending on the MIME type of the response.

You are probably getting a JSON object, so just run it through stringify:

var result = JSON.stringify(data);

Upvotes: 1

Related Questions