user169867
user169867

Reputation: 5870

What's the difference between text and html datatypes when using jQuery's ajax()

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?

Upvotes: 5

Views: 2075

Answers (2)

maček
maček

Reputation: 77826

Using this html

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

Differences

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

Upvotes: -2

Samuel
Samuel

Reputation: 1389

"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/

Upvotes: 4

Related Questions