[AJAX] Introduire ajax dans une page html
Bonjour noble développer
Je viens de réaliser une petite page HTML avec AJAX, mais quand j'ai voulu introduire cette page dans une autre page HTML, ça marche bien avec une iframe mais juste en local, quand je déplace ma page chez un hébergeur ça ne marche plus.
Même en utilisant la fonction include ça ne marche pas
Voila le code de ma page AJAX :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
| <!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<script type="text/javascript">
function getXMLHttpRequest() {
var xhr = null;
if (window.XMLHttpRequest || window.ActiveXObject) {
if (window.ActiveXObject) {
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
} else {
xhr = new XMLHttpRequest();
}
} else {
alert("Votre navigateur ne supporte pas l'objet XMLHTTPRequest...");
return null;
}
return xhr;
}
</script>
<script type="text/javascript">
<!--
function request(oSelect) {
var value = oSelect.options[oSelect.selectedIndex].value;
var xhr = getXMLHttpRequest();
xhr.onreadystatechange = function()
{
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0))
readData(xhr.responseXML , value);
};
xhr.open("POST", "type.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("id=" + value);
}
function readData(oData , value) {
//var value = oSelect.options[oSelect.selectedIndex].value;
var nodes = oData.getElementsByTagName("item");
var oSelect = document.getElementById("type");
var oOption, oInner;
oSelect.innerHTML = "";
for (var i=0, c=nodes.length; i<c; i++) {
if(nodes[i].getAttribute("value")==1)
{
if(nodes[i].getAttribute("id")=="exam")
oInner = document.createTextNode(nodes[i].getAttribute("id")+" & tp");
else
oInner = document.createTextNode(nodes[i].getAttribute("id"));
oOption = document.createElement("option");
oOption.value = nodes[i].getAttribute("id")+"?"+value;
oOption.appendChild(oInner);
oSelect.appendChild(oOption);
}
}
}
//-->
</script>
<script type="text/javascript">
<!--
function requestt(oSelect) {
var value = oSelect.options[oSelect.selectedIndex].value;
var xhr = getXMLHttpRequest();
xhr.onreadystatechange = function()
{
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0))
redData(xhr.responseXML,value);
};
xhr.open("POST", "exco.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("id=" + value);
}
function redData(oData ,value ) {
//var value = oSelect.options[oSelect.selectedIndex].value;
var nodes = oData.getElementsByTagName("item");
var oSelect = document.getElementById("exco");
var oOption, oInner;
oSelect.innerHTML = "";
for (var i=0, c=nodes.length; i<c; i++)
{
oOption = document.createElement("option");
oInner = document.createTextNode(nodes[i].getAttribute("nom"));
oOption.value = nodes[i].getAttribute("id")+"?"+value;
oOption.appendChild(oInner);
oSelect.appendChild(oOption);
}
}
//-->
</script>
<script type="text/javascript">
<!--
function lien(id)
{
var value = id.options[id.selectedIndex].value;
var s=value.split("?");
alert("id="+s[0]+" table = "+s[1]+" prof= "+s[2]);
if(s[1]=="cours")
top.location="../Cours/cour.php?id="+s[0];
else
top.location="../4GLM/Affiche.php?id="+s[0];
}
</script>
<body>
<select id="prof" size="10" onchange="request(this);">
<?php
include_once 'AccB.php';
$Acc=new AccB();
$re="SELECT DISTINCT * FROM (SELECT prof FROM exam UNION SELECT prof FROM cours ) k;";
$Exr=$Acc->Select($re);
while($Lir=$Exr->fetch())
{?>
<option value="<?php echo $Lir[0]; ?>"> <?php echo $Lir[0]; ?></option>
<?php }?>
</select>
<select id="type" size="10" onchange="requestt(this);"></select>
<select id="exco" size="10" onchange="lien(this)"></select>
</body>
</html> |
quand j'utilise ça en local ça marche, mais pas chez l'hébergeur
Code:
1 2
|
<iframe align="right" width="500" height="200" frameborder="1" scrolling="no" src="barProf\index.php" name="iframe"></iframe> |