display html code of response returned by ajax, Jquery

html, javascript, jquery

Solution

try using the text() function. This will escape and display html code. http://api.jquery.com/text/

$.post('get_news.php', $("#gifForm").serialize(), function(data) {
  //Show HTML
  $('#output').html(data);
  //Show HTML code
  $('#output_code').text(data);
});

Problem

I have a jquery AJAX function which retrieves some HTML markup and displays it on the page. I would also like to display the html code of this HTML returned. I've looked around for a solution but not finding any. Can someone please help. Many thanks ``` $.post('get_news.php', $("#gifForm").serialize(), function(data) { //Show HTML $('#output').html(data); //Show HTML code $('#output_code').html(data); }); ```

Original source

Related problems