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.

2
  • 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") Commented Apr 30, 2014 at 21:17
  • have a look here Commented Apr 30, 2014 at 21:19

1 Answer 1

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()

Sign up to request clarification or add additional context in comments.

2 Comments

+1 for pointing to this feature. In callback you can query #targetDiv. For getting HTML title I think something with regex and this could be needed.
nrodic, I finally endded up with regex to find the title. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.