Trying to select a 'body' tag from html that is returned by get() request

后端 未结 2 1150
醉梦人生
醉梦人生 2020-12-21 02:26

I\'m making an ajax get call that returns me contents of html page. I\'m trying to select contents of the body tag but my selector returns an empty jquery objec

2条回答
  •  青春惊慌失措
    2020-12-21 03:07

    jQuery uses the document object model, not the "text" that makes up that model. You only have a big piece of text in the data element that hasn't been added to the document yet.

    $(body).html(data);
    

    ... assuming the data contains valid body code. It it's an entire HTML page, then you'll need to parse it for just the body content, e.g. using indexOf or somesuch.

提交回复
热议问题