Seguendo questa utile guida (http://antirez.com/articoli/spaghettiajax.html) ho creato delle funzioni ajax per fare delle richieste http.
rispetto alle funzioni di esempio ho la necessità di passare una variabile alla funzione myHandler2 .
(la variabile mi serve per passare il nome dell'id del div su cui vado a scrivere).
io pensavo fosse una cosa semplice ma non funziona....
provo a postare qui sotto le 3 funzioni se qualcuno ha voglia di darci un'occhiata.
la prima è rimasta identica a quella del tutorial
codice:
var myRequest = null;
function CreateXmlHttpReq2(handler) {
var xmlhttp = null;
try {
xmlhttp = new XMLHttpRequest();
} catch(e) {
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
xmlhttp.onreadystatechange = handler;
return xmlhttp;
}
alla seconda ho aggiunto il passaggio della variabile "nomediv"
codice:
function myHandler2(nomediv) {
if (myRequest.readyState == 4 && myRequest.status == 200) {
e = document.getElementById(nomediv);
e.innerHTML = myRequest.responseText;
}
}
la terza funzione, quella che invia le variabili al php, l'ho modificata in base alle mie esigenze
codice:
function display(nome) {
var num =document.forms[nome].num.value;
var nomediv =document.forms[nome].nomediv.value;
var url =document.forms[nome].url.value;
var r = Math.random();
myRequest = CreateXmlHttpReq2(myHandler2(nomediv));
myRequest.open("GET","secondo.php?num="+escape(num)+"&&url="+escape(url)+"&&rand="+escape(r));
myRequest.send(null);
}
L'errore che mi da' è questo myRequest has no properties