[Front-end reference] uses AJAX to implement functions like PHP include require commands

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.