0

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,

2 Answers 2

1

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);
Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

This answer is correct, i had to set the dataType to "text" instead of "xml". $.get(appCore.location, doThisFuntion, "text")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.