Line breaks in jQuery ajax html callback cause errors

前端 未结 2 1486
隐瞒了意图╮
隐瞒了意图╮ 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:23

    My HTML strings did not have any top-level text nodes, or so I thought... I found the issue was just extra whitespace. This has worked for me, and feels better than filtering out the empty nodes later:

    $($.parseHTML($.trim(html_string)))
    

提交回复
热议问题