0

So since I'm still a noob, I want to know how to get the output of a page via AJAX in JQuery. I managed to get the page data and output it as text:

   $.ajax({
    type: "POST",
    url: "myfile.html",
    success: function(data) {
        $("#change").text(data);
    },
    error: function (request, ajaxOptions, exception){
            alert(request.status);
            alert(exception);
        }    
});

But as you may or may not know, that pretty much just shows the source code of the page. Let's say for example that the contents of "myfile.html" are as follows:

<html>
  <body>
   Hello!
  </body>
</html>

How would I make it so that AJAX only outputs "Hello!"?

2 Answers2

1

Have you tried:

$(data).text();

So:

$('#change').html($(data).find('body').text());
vol7ron
  • 40,809
  • 21
  • 119
  • 172
1

This should answer your question - parse html string with jquery

Community
  • 1
  • 1
Roshan Mathews
  • 5,788
  • 2
  • 26
  • 36