html5 imports,html - HTML5 Imports not working - Stack Overflow

Myth丶恋晨 2022-10-04 14:54 110阅读 0赞

The correct to do this is through server side pages includes or through JavaScript.

PHP example:

Welcome to my home page!

Some text.

Some more text.

Javascript Example:

function loadXMLDoc() {

var xmlhttp = new XMLHttpRequest();

xmlhttp.onreadystatechange = function() {

if (xmlhttp.readyState == XMLHttpRequest.DONE ) {

if (xmlhttp.status == 200) {

document.getElementById(“myDiv”).innerHTML = xmlhttp.responseText;

}

else if (xmlhttp.status == 400) {

alert(‘There was an error 400’);

}

else {

alert(‘something else other than 200 was returned’);

}

}

};

xmlhttp.open(“GET”, “header.html”, true);

xmlhttp.send();

}

Javascript with JQuery Library:

$.ajax({

url: “header.html”,

success: function(data){

$(“myDiv”).html(data.responseText);

}

});

If you don’t want to get your hands dirty in js you can do the following using a script provided by w3schools:

w3IncludeHTML();

发表评论

表情:
评论列表 (有 0 条评论,110人围观)

还没有评论,来说两句吧...

相关阅读