Salve a tutti, dunque ho implementato una funzione che permette di iscriversi ad una parte diciamo riservata nel sito della società..quindi ho fatto una form con nome e pasw a dx se sei già iscritto e una parte iscriviti.
Il sito funziona con i div quindi a dx e sx sono div fermi quello in mezzo è quello che dinamicamente viene occupato.
dunque ho creato una funzione loadurl che funziona bene e che carica la parte centrale poi anche quella che interroga il db e vede se nome e psw esistono. e anche quella funziona
quella che crea casini è quando cerco di prendere i campi della form per scriverli sul db e fare entrare l'utente nell'area.
questo è il codice js che viene inserito nel file index.html
Codice PHP:
// JavaScript Document
function loadurl(dest) {
try {
xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) { /* do nothing */ }
xmlhttp.onreadystatechange = triggered;
xmlhttp.open("GET", dest);
xmlhttp.send(null);
}
function triggered() {
if (xmlhttp.readyState == 4) if (xmlhttp.status == 200)
document.getElementById("main").innerHTML = xmlhttp.responseText;
}
var obj;
var obj2;
//new init
//finish new
function GetXmlHttpObject()
{
var xmlhttp = null;
if(window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
// Gecko (Firefox, Moz), KHTML (Konqueror, Safari), Opera, Internet Explorer 7
}
else if(window.ActiveXObject)
{
try
{
xmlhttp = new ActiveXObject("MSXML2.XMLHTTP"); // Internet Explorer 6
}
catch(e)
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer 4,5
}
}
else
{
xmlhttp = null;
}
return xmlhttp;
}
//function istanzaXHR() {
// obj = window.XMLHttpRequest?new XMLHttpRequest():
// new ActiveXObject("Microsoft.XMLHTTP");
//
// return obj;
//}
obj=GetXmlHttpObject();
obj2=GetXmlHttpObject();
function onStateChange() { // Cambiamento Stato
if (obj.readyState == 4) { // Caricamento Avvenuto
if (obj.status == 200) { // con successo
dest = obj.responseText;
loadurl(dest);
//document.getElementById("main").innerHTML=obj.responseText; // risultato
} else {
document.getElementById("main").innerHTML="?";
alert("Errore: "+obj.statusText);
}
}
}
function onStateChange2() { // Cambiamento Stato
//alert("status cambiato:"+obj2.status);
if (obj2.readyState == 4) { // Caricamento Avvenuto
if (obj2.status == 200) { // con successo
dest1 = obj2.responseText;
loadurl(dest1);
//document.getElementById("main").innerHTML=obj.responseText; // risultato
} else {
//fare pagina di errore
document.getElementById("main").innerHTML="?";
alert("Errore: "+obj2.statusText);
}
}
}
function invia() {
inviaXHR(obj);
}
function registra() {
if(Convalida()){
//alert("ok convalidata");
// obj2 = newAjax();
if (obj2 != false) {
registraXHR(obj2);
} else {
alert ("obj2:"+obj2+"mi spiace il browser non permette interazione");
}
}
}
function inviaXHR(obj) {
try {
obj.open("POST", "http://www.sito.it/conn/autenticaU.asp", true); // Preparazione comunicazione
document.getElementById("main").innerHTML=".......attendere......."; // caricamento in corso...
obj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
obj.onreadystatechange = onStateChange;
nome=escape(document.login.nome.value); // valore user
password=escape(document.login.password.value); // valore psw
obj.send("nome="+nome+"&password="+password); // Trasferimento
} catch (e) {
document.getElementById("main").innerHTML="?";
alert("Errore: "+e);
}
}
function registraXHR(obj2) {
try {
obj2.open("POST", "http://www.sito.it/conn/registraU.asp", true);
// Preparazione comunicazione
document.getElementById("main").innerHTML=".......attendere.......";
// caricamento in corso...
obj2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
obj2.onreadystatechange = onStateChange2;
nome2=escape(document.iscriviti.nome.value); // valore user
cognome=escape(document.iscriviti.cognome.value); // valore psw
email=escape(document.iscriviti.email.value); // valore user
bday=escape(document.iscriviti.bday.value); // valore psw
f=escape(document.iscriviti.F.checked); // valore user
citta=escape(document.iscriviti.citta.value); // valore psw
via=escape(document.iscriviti.via.value); // valore user
password2=escape(document.iscriviti.password.value); // valore psw
obj2.send("nome="+nome2+"&cognome="+cognome+"&email="+email+"&bday="+bday+"&f="+f+"&citta="+citta+"&via="+via+"&password="+password2); // Trasferimento
} catch (e) {
// fare pagina di errore
//alert(obj2);
document.getElementById("main").innerHTML= "..errore di connessione..";
alert("Errore: "+e);
}
}
poi nel file della form c'è una onlcik su registra che chiama la funzione registra()
(come nello spazio a dx per il login)
il problema è che non funziona su opera e IE mentre funziona perfetta su firefox..
la funzione di GetXmlHttpObject l'ho presa da Andrea (cavicch.)
aiuto aiuto ma che errore sto facendo... lo so che è un errore macroscopico e che non vedo..
ma vi prego qualcuno mi aiuti... grazi egracias