显示由ajax,Jquery返回的html代码 [英] display html code of response returned by ajax, Jquery
本文介绍了显示由ajax,Jquery返回的html代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个jQuery AJAX函数,它检索一些HTML标记并将其显示在页面上。我也想显示返回的HTML的html代码。我已经四处寻找解决方案,但没有找到任何解决方案。有人可以请帮助。非常感谢
$。post('get_news.php',$(#gifForm)。serialize(),function数据){
//显示HTML
$('#output')。html(data);
//显示HTML代码
$('#output_code ').html(data);
});
解决方案
尝试使用强>功能。这将转义并显示html代码。 http://api.jquery.com/text/
<$ p $($'$ $ $ $ $ $ $ $ $ $($'$ $ $ $ $'$'$ $ $ $ '#output')。html(data);
//显示HTML代码
$('#output_code').text(data);
});
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);
});
解决方案
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);
});
这篇关于显示由ajax,Jquery返回的html代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文