У меня проблема с JS или Ajax (я не знаю).
У меня есть кнопка на веб-странице (html), которая связана с событием JS onClick. Этот JS отлично работает для любого браузера, за исключением Firefox 3.0.x
Я не знаю, в чем проблема.
Я прилагаю код, чтобы кто-то мог мне что-то сказать об этом.
Заранее спасибо.
С.
var currLanguage = "en";
var request;
var queryString;
function confermaSalvataggio(reservationsList)
{
var messaggioHeader = new Array();
var messaggioFooter = new Array();
messaggioHeader['it'] = "ATTENZIONE! I dati caricati nel pannello non sono più aggiornati a causa di prenotazioni o cancellazioni avvenute dall'apertura del pannello stesso.\n\n";
messaggioFooter['it'] = "\nContinuare con le VOSTRE modifiche ? Premendo OK i vostri dati verranno salvati e dovrete verificarne la correttezza in seguito manualmente. Premendo ANNULLA (consigliato) verrete riportati al pannello dove potrete appuntarvi i dati appena inseriti, ricaricare il pannello (manualmente) ed inserirli nuovamente mantenendo il loro stato congruente con le prenotazioni/cancellazioni appena giunte";
messaggioHeader['en'] = "CAUTION! Data loaded on the panel isn't up to date due to reservations or cancellations occurred since panel open. \n\n"
messaggioFooter['en'] = "\nDo you want to continue with changes ? By clicking OK YOUR data will saved and, then, you'll have to verify the correctness in a manual way. By clicking CANCEL (recommended) you'll come back on the panel where you can clip out data just inserted, reload the panel (manually) and insert again data keeping data state congruent with reservations/cancellations just come";
messaggioHeader['fr'] = messaggioHeader['en'];
messaggioFooter['fr'] = messaggioFooter['en'];
messaggioHeader['es'] = messaggioHeader['en'];
messaggioFooter['es'] = messaggioFooter['en'];
messaggioHeader['de'] = messaggioHeader['en'];
messaggioFooter['de'] = messaggioFooter['en'];
if ( reservationsList != "\n" )
{
var messaggio = messaggioHeader[currLanguage]+reservationsList+messaggioFooter[currLanguage];
var flag = confirm(messaggio);
if (flag)
{
document.tariffe.submit();
}
}
else
{
document.tariffe.submit();
}
}
function handleSaveResponse()
{
if (request.readyState == 4)
{
if (request.status == 200)
{
var response = this.responseText;
confermaSalvataggio(response);
}
else
{
//alert("Risposta del web service: " + request.status);
}
}
}
function initializeRequestObject()
{
var msxmlhttp = new Array('Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP');
if (typeof XMLHttpRequest != "undefined")
{
request = new XMLHttpRequest();
}
else
{
for (var i = 0; i < msxmlhttp.length; i++)
{
try
{
request = new ActiveXObject(msxmlhttp[i]);
}
catch (e)
{
request = null;
}
}
}
}
function initReq(reqType, url, bool)
{
if (request)
{
try
{
request.open(reqType, url, bool);
}
catch (e)
{
errorsString = 'Errore nella funzione initReq(), metodo request.open: ' + e;
alert(errorsString);
}
try
{
request.onreadystatechange = handleSaveResponse;
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
}
catch (e)
{
errorsString = "Errore nella funzione initReq(), metodo request.onreadystatechange: " + e;
alert(errorsString);
}
try
{
request.send(queryString);
}
catch (e)
{
errorsString = "Errore nella funzione initReq(), metodo request.send: " + e;
alert(errorsString);
}
}
}
function httpRequest(reqType, url, asynch)
{
initializeRequestObject();
if (request)
{
initReq(reqType, url, asynch);
}
else
{
notifyError("Errore in httpRequest(): oggetto XmlHttpRequest non inizializzato correttamente");
}
}
function controlReservations(hotel_id,data_server,data_da,data_a,lingua)
{
try
{
queryString = "hid=" + hotel_id + "&ds=" + data_server + "&dd=" + data_da + "&da=" + data_a + "&lingua=" + lingua;
httpRequest("POST", "hotelLastReservations", false);
// MI SERVIRANNO !?!? //
//pagina = base_url + "/" + entity
//alert(pagina);
//window.location = pagina;
// MI SERVIRANNO !?!? //
}
catch (e)
{
notifyError("Errore in toggleAttiva(): " + e);
}
}
Я только что нашел решение. Firefox <4 не поддерживает синхронный обработчик ajax. Если я переключусь на асинхронный. обработчик работает правильно. </p>