Gibbs
Gibbs

Reputation: 22956

Load a html into a div - which one should be used at what situation?

To load a html page into a div

1) HTML Embedded Object Element

2) Jquery load

3) Ajax

Which one should be used and when should be used? Because we can achieve this by using any one of these three options. But I am not clear what should be used in what situations?

Upvotes: 1

Views: 44

Answers (2)

Niki van Stein
Niki van Stein

Reputation: 10724

1) HTML Embedded Object Element

You can use embed to add rich content, like videos, images, pdfs, etc.

2) Jquery load

You can use .load() when you want html, json, xml or any other content, and an advantage of .load() is that you can select wich portion of the page you would like to load.

A difference between load and embed is that you determine when the data is loaded, if you embed an object it will be loaded when the page loads (and can also cause page load issues because of that).

3) Ajax

Is behind the scenes exactly the same as .load(), but depending on the exact situation load() might be more convenient, and ajax more flexible.

Upvotes: 2

Bit68
Bit68

Reputation: 1546

Embedd when you are getting data from a third party, EX: youtube video, soundloud song, etc...

and load ajax if you are loading non formated html data (IE: json or xml).

Upvotes: 0

Related Questions