AJAX with Firefox it works, with IE or SAFARI not
Hello,
I've searched for more than 6 hours, but I can't find the problem. I hate it!!!
I've written a code, which should get via AJAX the actual status of my file upload. In Firefox it works fine and the status grow up slowly. In IE for example, nothing happens... do you have any ideas?
the first ajax (the get statement) works fine, i think the problem is ihte second one...
this is my code (sorry the comments are in german)
- // Wenn das Dokument geladen ist
$(document).ready(function(){
// lokale Deklaration
var lv_userid;
var lv_uploadid;
var lv_loaded = 0;
var lv_uploaded = 0;
var lv_size_comp = 0;
var lv_size_load = 0;
var lv_uploadpercent = 0;
var lv_uploadstatus = "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"50\" valign=\"middle\">";
lv_uploadstatus += "<img src=\"templates/images/uploadrunner.gif\" width=\"30\" height=\"30\" /></td>";
lv_uploadstatus += "<td width=\"100\" align=\"left\" valign=\"middle\" id=\"text_uploadpercent\" >0%</td>";
lv_uploadstatus += "<td align=\"left\" valign=\"middle\" class=\"text_bold\">Die Datei wird auf unseren Server geladen,<br /> bitte haben Sie einen Moment geduld.";
lv_uploadstatus += "</td></tr></table>";
// Verküpfe Uploadformular mit weiteren Funktionen
$('#btn_upload').click( function(){
// Deaktiviere den Knopf, damit er nicht nochmals geklickt werden kann
$(this).attr("disabled", true);
// Hole UserID und UploadID vom Server und stelle Sie in die Formularfelder
$.get('index.php?do=registerUpload', function(xml_data){
// Versteckte Forumlarfelder mit Userid + Uploadid füllen
lv_userid = $(xml_data).find("userid").text();
lv_uploadid = $(xml_data).find("uploadid").text();
// Hänge Zieldatei an Uploadformular
$('#frm_fileupload').attr("action", "../cgi-bin/upload.pl?userid=" + lv_userid + "&uploadid=" + lv_uploadid);
//document.getElementByID("frm_fileupload").setAttribute("action", "../cgi-bin/upload.pl?userid=" + lv_userid + "&uploadid=" + lv_uploadid);
// Formular abschicken
$('#frm_fileupload').submit();
// Formular durch Uploadinformationen ersetzen
$('#uploadform').html(lv_uploadstatus);
test(lv_userid, lv_uploadid);
});
});
// Hole den Status, solange bis File fertig gelanden ist
function test(lv_userid, lv_uploadid){
var lv_loaded = 0;
var lv_uploaded = 0;
var lv_size_comp = 0;
var lv_size_load = 0;
var lv_uploadpercent = 0;
//while(lv_uploadpercent != 100){
// Hole aktuellen Status
$.ajax({ type: "GET",
url: "index.php",
async: false,
data: "do=getUploadStatus&uploadid=" + lv_uploadid,
success: function(xml_data){
// Weise die Ergebnis lokalen Variablen zu
lv_uploaded = $(xml_data).find("uploaded").text();
lv_size_load = $(xml_data).find("size_load").text();
lv_size_comp = $(xml_data).find("size_comp").text();
// Prüfe ob schon gerechnet werden kann -> beim ersten Ruf könnte size_load noch leer sein
if(lv_size_load > 0 && lv_size_comp > 0){
// Berechne Prozent, wenn noch nicht komplett geladen
if(lv_uploaded == 0){
lv_uploadpercent = Math.round(lv_size_load * 100 / lv_size_comp);
if(lv_uploadpercent < 1){
lv_uploadpercent = 0;
}
} else {
lv_uploadpercent = 100;
}
} else {
lv_uploadpercent = 0;
}
// Ersetze Prozentanzeige durch neuen Wert
$('#text_uploadpercent').html(lv_uploadpercent + "%");
if(lv_uploadpercent < 99){
test(lv_userid, lv_uploadid);
}
}
})
//}
}
});
best regards,
paulaner