Alternative Ajax au include du php
Bonjour,
Tous est dans le titre...ou presque.
En effet, je cherchais une alternative au include du php.
Ajax semble être une solution recommandée.
Je m'y suis donc mis modestement et j'ai trouvé ce code.
Il fait l'affaire à un détails prêt, j'aimerais que la page se charge seule sans bouton on clicck...
Quelqu'un pourrait il me dire comment faire svp?
Premiere page appellée header.html
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
</head>
<body>
entete |
deuxième page appellée: footer.html:
Code:
1 2 3 4 5
|
pied de page
</body>
</html> |
Code html:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").load("header.html");
$("#div2").load("footer.html");
});
});
</script>
</head>
<body>
<div id="div1"></div>
<button>Get External Content</button>
corps
<div id="div2"></div>
</body>
</html> |
Et accessoirement, j'aimerais savoir si le code est correcte?
:)