Salve a tutti...io sto creando una pagina in html che grazie a javascript e ajax che se non ha un parametro ?name nell'url (esempio: index.htm?nome=vacanze) carica il file tabella.php (che se non riceve nessun nome restituisce la lista di nomi)... invece se ha un nome carica sempre il file php ma inviando il parametro nome (per esempio tabella.php?nome=vacanze)... ottenendo come risultato una tabella con delle immagini...
ho provato a farlo cosi documentandomi in internet (sono un novizio in ajax):
Codice PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="generator" content="" />
<link href="stile.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="utility.js"></script>
<script type="text/javascript" language="JavaScript">
<!--hide
var folder;
var file;
function prendiElementoDaId(id_elemento) {
var elemento;
if(document.getElementById)
elemento = document.getElementById(id_elemento);
else
elemento = document.all[id_elemento];
return elemento;
};
// funzione per assegnare un oggetto XMLHttpRequest
function assegnaXMLHttpRequest() {
var
XHR = null,
browserUtente = navigator.userAgent.toUpperCase();
if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
XHR = new XMLHttpRequest();
else if(window.ActiveXObject && browserUtente.indexOf("MSIE 4") < 0) {
if(browserUtente.indexOf("MSIE 5") < 0)
XHR = new ActiveXObject("Msxml2.XMLHTTP");
else
XHR = new ActiveXObject("Microsoft.XMLHTTP");
}
return XHR;
};
// oggetto di verifica stato
var readyState = {
INATTIVO: 0,
INIZIALIZZATO: 1,
RICHIESTA: 2,
RISPOSTA: 3,
COMPLETATO: 4
};
// array descrittivo dei codici restituiti dal server
// [la scelta dell' array è per evitare problemi con vecchi browsers]
var statusText = new Array();
statusText[100] = "Continue";
statusText[101] = "Switching Protocols";
statusText[200] = "OK";
function cambia(num){
var namet='t'+num;
var namel='l'+num;
if (document.all[namet].style.display=="none") {
prendiElementoDaId('t'+num).value=prendiElementoDaId('c'+num).value;
document.all[namet].style.display = "";
document.all[namel].style.display = "none";
document.all['post'+num].style.display = "";
prendiElementoDaId('submit'+num).setAttribute("value","Annulla");
}
else {
document.all[namel].style.display = "";
document.all[namet].style.display = "none";
document.all['post'+num].style.display = "none";
prendiElementoDaId('t'+num).value=prendiElementoDaId('c'+num).value;
prendiElementoDaId('submit'+num).setAttribute("value","Rinomina");
}
}
function getFolder(){
var param = window.location.search.substr(1).split(/\&/);
for(var i=0; i<param.length; i++) {
var nom_val = param[i].split(/\=/);
if (nom_val[0]=='nome'){
folder=unescape(nom_val[1]);
}
else if (nom_val[0]=='file'){
file=unescape(nom_val[1]);
}
}
}
function caricatabella(){
var ajax = assegnaXMLHttpRequest();
var elemento = prendiElementoDaId('erase');
var usaLink = true;
getFolder()
if (file!=undefined){
//elimina(file);
}
if(ajax) {
var link="tabella.php";
var nomeFile="";
if (folder!=undefined){
nomeFile += "?nome=" + escape(folder);
}
alert(nomeFile);
usaLink = false;
elemento.innerHTML="<p Style=\"text-align:center\">Attendere prego</p>";
ajax.open("POST", link+nomeFile, true);
ajax.setRequestHeader("connection", "close");
ajax.onreadystatechange = function() {
if(ajax.readyState === readyState.COMPLETATO) {
if(statusText[ajax.status] === "OK")
elemento.innerHTML = ajax.responseText;
else {
elemento.innerHTML = "Impossibile effettuare l'operazione richiesta.
";
elemento.innerHTML += "Errore riscontrato: " + statusText[ajax.status];
}
}
}
ajax.send(null);
}
return usaLink;
}
//-->
</script>
</head>
<body onload="javascript:caricatabella()">
<div id="erase">
</div>
</body>
</html>
l'ho provato in firefox e funziona perfettamente...vengono inviati i parametri e il risultato è corretto...
ma se provo a utilizzarlo in internet explorer non funziona! cioè finche richiedo la pagina tabella.php funziona perfettamente...ma quando invio tabella.php?nome=qualcosa la pagina php non riceve niente in ritorno! come è possibile?