Using AJAX to implement commands like PHP include require
Requirements introduction in the writing of the page, a navigation may be n pages to use, each page needs to copy and paste one in, once the need to change the HTML code is hard, each has to be changed again. If there is a lot of demand, repeated changes, it is simply torture AH (although this situation is generally not met, but I always meet. )
Look directly at the code
<script id= "Ajax-header" type= "Text/javascript" >//create an outer div from JS$ ("#ajax-header"). Before (' <div id= ' include-head-php ' ></div> '); $ (document). Ready (function(){//$ ("#include-head-php"). Load ("head.html");//callback function $("#include-head-php"). Load ("head.html",function(RESPONSETXT,STATUSTXT,XHR) {if(statustxt== "Success") { //Yes, this is the legendary shell Dafa! $ ("#include-head-php"). Children (). Unwrap (); }Else if(statustxt== "Error") { $("#include-head-php"). HTML ("Component loading failed here!"). "); Alert ("Error:" + xhr.status + ":" +xhr.statustext); } }); }) </script>
Write the head code in head.html so that the other pages are referenced directly from the above code. I think it can also be organized into a method, here directly to the call can be called, there is no time to do it.
It is important to note that if you write only HTML structure code in head.html, then the style can be applied to these structures, but if it is dynamic, JS does not seem to work. JS must be put in the piece.
If the front-end frame, such as Amazeui, is not measured, the entire page must be
Why not use an IFRAME?
Forgot. I didn't know what to think, so it was useless. I'll talk later.
Or slowly delve into it, I heard that some front-end framework can directly support the function that would be good.
[Front-end reference] uses AJAX to implement functions like PHP include require commands