1

I use Ajax to get info from within another page, but not display this page. Here is the code

$.ajax({
    url: 'another-page.html',
    dataType: 'html',
    success: function (data) {

       //how to get the html title contained in data?
       //how to get an element with ID contained in data?

    }
});

I feel this should have been answered somewhere, but I was unable find it. Sorry if this is a duplicate. I will delete it if there is answer at SO already.

Many thanks.

curious1
  • 14,155
  • 37
  • 130
  • 231
  • 1
    do a `console.log(data)` and inspect the returned value, then find a way to get the title.. probably the html content is inside a property.. so you will do something like `$(data.propName).find("title")` – BeNdErR Apr 30 '14 at 21:17
  • have a look [here](http://stackoverflow.com/questions/20007721/parsing-returned-html-from-jquery-ajax-request) – BeNdErR Apr 30 '14 at 21:19

1 Answers1

2

If I understood right your question to need to parse the remote document or select a portion .You can use the load method to select a certain Div, title within that document

$( "#targetDiv" ).load( "remotePage.html #title" );

Have a look at load()

Awena
  • 1,002
  • 5
  • 20
  • 43
  • 2
    +1 for pointing to this feature. In callback you can query `#targetDiv`. For getting HTML `title` I think something with regex and [this](http://stackoverflow.com/a/10585079/551322) could be needed. – nrodic Apr 30 '14 at 21:46
  • nrodic, I finally endded up with regex to find the title. Thanks! – curious1 Apr 30 '14 at 22:10