/* Funzione di stampa messaggi in debug su console firefox - se attiva */ function debugX(mex) { try { console.debug(mex); } catch(e) { //Console non attiva o browser non supportato } } /* Funzione generica di richiamo ajax */ function ajaxCall(dataToSend, url, mex, out) { var esito = false; mex.html("...richiesta in corso..."); $.ajax({ success : function(msg){ switch(msg.substring(0,4)) { case "#OK|": mex.html(" "); var pos = msg.indexOf("||"); if (pos == -1) { out.html(msg.substring(4)); } else { //Risposta AJAX dal login (unica response con ||) pos2 = msg.indexOf("|", pos+2); stato = msg.substring(pos+2, pos2); if (stato == "0000") { //Login/Logout corretto => Tutti gli output del login.php riportano uno stato per consentire l'esecuzione della attivaLogin() } else if (stato == "1000") { alert('Nome utente o password non riconosciuti'); } else if (stato == "1001") { alert('Attenzione: Account non attivo'); } else if (stato == "1002") { alert('Nome utente non valido: utilizzare un indirizzo email corretto'); } else { alert('Impossibile modificare lo stato di autenticazione.\nRiprovare pił tardi'); } out.html(msg.substring(pos2+1)); attivaLogin(); } esito = true; break case "#NV|": mex.html("<<<Dati non validi - ricontrollare i campi>>>"); if (out.attr("id") != mex.attr("id")) { //Aggiornare il contenitore con il response (dettaglio campi) out.html(msg.substring(4)); } esito = false; break; case "#DB|": mex.html("<<<Impossibile leggere/scrivere i dati - riprovare più tardi>>>"); esito = false; break; default: mex.html("<<<Errore generico>>>"); debugX(msg); esito = false; } }, error : function (xhr, ajaxOptions){ mex.html("<<<Errore generico>>>"); debugX(xhr.status + " - " + xhr.responseText); esito = false; }, type: "POST", data: dataToSend, url: url, async: false }); return esito; }