5

What does jQuery do differently when you specify the datatype as html as opposed to text. I haven't seen a difference but there must be some subtleties I'm missing. If I wish to return a portion of an html page as a string does it matter which I use?

2 Answers 2

4

"html": Returns HTML as plain text; included script tags are evaluated when inserted in the DOM. "text": A plain text string.

So really the only difference is if you have script tags.

source: http://api.jquery.com/jQuery.ajax/

Sign up to request clarification or add additional context in comments.

2 Comments

That's how I would have interpreted it too, but I do have script tags and they run even with "text" as the datatype. At least in IE8 & FF3.6
it seems by default jQuery tries to figure out the type for you. i believe text is used to avoid this. so instead of jQuery trying to figure out if it's JSON, xml, script or html it just hands you plain text without worrying about it. (jQuery likes to worry...)
-2

Using this html

<div id="foo">
  <span>hello world</span>
</div>

Differences

$("#foo").text(); //=> hello world
$("#foo").html(); //=> <span>hello world</span>

2 Comments

I think you misunderstood the question.
Yeah, sorry macek I might not have been clear enough but I was asking about the datatype parameter on the ajax function in jQuery.

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.