javascript - .load() 等 Ajax 函数从 HTML 中去除注释。我怎样才能保留评论?

标签 javascript ajax jquery

例如,$('#some-div').load('http://foo.bar #content')将检索 #content来自 http://foo.bar但所有 HTML <!--comments-->剥离。

如何检索 #content 的内容包括任何评论?

最佳答案

来自jQuery manual :

jQuery uses the browser's .innerHTML property to parse the retrieved document and insert it into the current document. During this process, browsers often filter elements from the document such as <html>, <title>, or <head> elements. As a result, the elements retrieved by .load() may not be exactly the same as if the document were retrieved directly by the browser.

所以你应该使用$.get()检索 HTML 而不是 $.fn.load()

关于javascript - .load() 等 Ajax 函数从 HTML 中去除注释。我怎样才能保留评论?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5231351/

相关文章:

javascript - Protractor - 无法读取 EC.textToBePresentInElement 的未定义属性绑定(bind)

javascript - 切换仅显示单击的一项

javascript - 无法调用未定义 Handlebars 问题的方法 'match'

javascript - 查找通用项的 Src 属性

php - 我有一个表,我用它通过 ajax 或 jquery 更新 mysql,适用于 firefox、opera、chrome 和 safari,但不适用于 IE8

php - 通过 jquery ajax 将多维数组输入从 html 解析为 php

javascript - 发出 JSON RPC API 的 GET 请求而不是 POST 请求

javascript - 使用动态数据 json 初始化 isotope

javascript - WordPress AJAX 加载页面内容

jquery - xhr.status 为 8 在 IE8 中意味着什么?