0

I'm trying to return html page throught ajax response, the response return html codes of the page if I alert. I want to read the inner html of those html codes to get and values / contents. How can I achieve that if ajax request succeed. Thanks in advance.

// ajax

    let req = $.ajax({
        url: '/page',
        method: 'GET',
        dataType: 'html'
    });
    req.done(function(response){
        // console.log(response)
        // $(response).find('title').html();
        // $(response).find('.my-header').html();
        alert(response);
    });

//html response

<head>
    <title>my pagename</title>
</head>
<body>
    <div class="my-header">HEADER TEXT</div>
</body>
ven
  • 185
  • 1
  • 18

1 Answers1

1

Try using filter() instead of find(). jQuery strips out the head of a full page

const title = $(response).filter('title').text();
charlietfl
  • 170,828
  • 13
  • 121
  • 150