jQuery: Load Page in a Div

Loading an external page in a div using jQuery is as simple as calling the jQuery Load method. The Load() method loads data from the server and places the returned HTML into the matched element.
Assuming you have a Div called ‘divOne’ and an anchor link called ‘ext’. On clicking the anchor, a different page ‘from the same domain’ gets loaded.

jQuery Load External Page

See a Live Demo. When you click the link, observe how the entire page loads into this div.

Note: If you are trying load an external page from a ‘different domain’, you would either need to proxify data through your own server or use JSON-P. It will be a cross-domain call. Read this document to learn more.

4 comments:

  1. Actually, your example doesn't work - I'm finding that the entire div is replaced with the new content; it doesn't go into the div as expected.

    ReplyDelete
  2. I disagree, it works fine for me.

    ReplyDelete