Line breaks in jQuery ajax html callback cause errors

前端 未结 2 1511
隐瞒了意图╮
隐瞒了意图╮ 2021-01-12 23:36

I am returning a large chunk of HTML from an $.ajax call. The string coming from PHP has two line breaks at the beginning, e.g.

$data = \"

<         


        
2条回答
  •  情深已故
    2021-01-13 00:31

    The problem seems to be caused by the text node in the collection you can filter it out with .filter('*')

    var $html = $($.parseHTML(data)).filter('*');
    

提交回复
热议问题