开发者

Ajax functions like .load() strip out comments from the HTML. How can I keep the comments?

开发者 https://www.devze.com 2023-02-15 06:59 出处:网络
For example, $(\'#some-div\').load(\'http://foo.bar #content\') will retrieve #content from http://foo.bar but with all HTML <!--开发者_JS百科comments--> stripped.

For example, $('#some-div').load('http://foo.bar #content') will retrieve #content from http://foo.bar but with all HTML <!--开发者_JS百科comments--> stripped.

How can I retrieve the contents of #content including any comments?


From the 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.

So you should use $.get() to retrieve the HTML instead of $.fn.load()

0

精彩评论

暂无评论...
验证码 换一张
取 消