Saturday, 15 June 2013

javascript - Loading a page via Ajax into Div Best Practice? -


I am using the method below to load a remote page in a device on this page. <> $ ('# results') preload ('www.myurl.com/results.html').

I'm curious, is it a bad practice to load a fully formatted HTML page into another page? My concern is more to load css or additional javascript, in which the other elements on the primary page can be overwritten.

I have not had any problems during my initial tests, I am not sure that this is the best practice.

To illustrate: If I have a primary page,

    

and the results.html code that looks like this:

  & lt; Html & gt; & Lt; Top & gt; & Lt; Script src = "jquery.js" & gt; & Lt; / Script & gt; & Lt; Link href = "myResults.css" rel = "stylesheet" type = "text / css" & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Header & gt; & Lt; H1 & gt; My results page & lt; / H1> & Lt; / Header & gt; ... & lt; / Body & gt;   

Will CSS and JS overwrite each other, or will page 2 serve as separate entities?

This will work fine and the browser will handle it properly:

< P> ... Browsers often filter elements from the document such as & lt; Html & gt; , & lt; Title & gt; , or & lt; Head & gt; element As a result, the elements obtained by .load () can not be exactly the same, such as the documents were recovered by the browser directly.

However, this is probably the best practice to specify the element in the returned HTML in which you want to insert:

  $ ('# remoteContainer '). Load ('www.myurl.com/results.html #containerDiv');    

No comments:

Post a Comment