Ajax und der FF

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Ajax und der FF

    Hallo,

    derzeit versuche ich mich an einem kleinen Ajax Chat für eine Private Seite.
    Soweit läuft auch alles im Opera aber im Firefox nicht.

    Ich habe 2 Ajax Request

    Quellcode

    1. function ajaxFunction(){
    2. var ajaxRequest; // The variable that makes Ajax possible!
    3. try{
    4. // Opera 8.0+, Firefox, Safari
    5. ajaxRequest = new XMLHttpRequest();
    6. } catch (e){
    7. // Internet Explorer Browsers
    8. try{
    9. ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    10. } catch (e) {
    11. try{
    12. ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
    13. } catch (e){
    14. // Something went wrong
    15. alert("Your browser broke!");
    16. return false;
    17. }
    18. }
    19. }
    20. return ajaxRequest;
    21. }
    22. function showData() {
    23. //alert("i m here");
    24. htmlRequest = ajaxFunction();
    25. if (htmlRequest==null){ // If it cannot create a new Xmlhttp object.
    26. alert ("Browser does not support HTTP Request"); // Alert Them!
    27. return; // Returns.
    28. } // End If.
    29. htmlRequest.onreadystatechange = function(){
    30. if(htmlRequest.readyState == 4){
    31. document.getElementById("shoutarea").innerHTML = htmlRequest.responseText;
    32. var obj = document.getElementById('shoutarea');
    33. obj.scrollTop = obj.scrollHeight;
    34. }
    35. }
    36. htmlRequest.open("GET", "index.php?mode=outputinfo", true);
    37. htmlRequest.send(null);
    38. }
    39. showData();
    40. setInterval("showData()",1000);
    41. function showsData() {
    42. //alert("i m here");
    43. htmlRequest = ajaxFunction();
    44. if (htmlRequest==null){ // If it cannot create a new Xmlhttp object.
    45. alert ("Browser does not support HTTP Request"); // Alert Them!
    46. return; // Returns.
    47. } // End If.
    48. htmlRequest.onreadystatechange = function(){
    49. if(htmlRequest.readyState == 4){
    50. document.getElementById("onlinearea").innerHTML = htmlRequest.responseText;
    51. var obj = document.getElementById('onlinearea');
    52. obj.scrollTop = obj.scrollHeight;
    53. }
    54. }
    55. htmlRequest.open("GET", "index.php?mode=outputinfos", true);
    56. htmlRequest.send(null);
    57. }
    58. showsData();
    59. setInterval("showsData()",1000);
    Alles anzeigen


    function showData() ruft die Chat Texte Live ab, function showsData() die User Online Liste

    Im Opera läuft alles soweit. Die Texte haben zwar ne Verzögerung beim 1 Aufruf von ca 10 Sec aber es läuft.
    Im Firefox allerdings habe ich in beiden DIV Spalten die User Online Liste.

    So ganz blicke ich auf dem JS Feld noch nicht ganz durch und hoffe auf eure Hilfe.
  • HiHo,

    So, nach durchstöbern des Forum bin ich auf easy-coding.de/wiki/php/upload-fortschritt-mit-php-ajax.html gestossen und habe mir diese Funktion dex JS für die User Online Liste zu eigen gemacht.
    Nun habe ich 2 unterschiedliche funktionen für den ajax request

    Das wäre einmal für die Texte

    Quellcode

    1. // JavaScript Document
    2. function ajaxFunction(){
    3. var ajaxRequest; // The variable that makes Ajax possible!
    4. try{
    5. // Opera 8.0+, Firefox, Safari
    6. ajaxRequest = new XMLHttpRequest();
    7. } catch (e){
    8. // Internet Explorer Browsers
    9. try{
    10. ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    11. } catch (e) {
    12. try{
    13. ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
    14. } catch (e){
    15. // Something went wrong
    16. alert("Your browser broke!");
    17. return false;
    18. }
    19. }
    20. }
    21. return ajaxRequest;
    22. }
    23. function showData() {
    24. //alert("i m here");
    25. htmlRequest = ajaxFunction();
    26. if (htmlRequest==null){ // If it cannot create a new Xmlhttp object.
    27. alert ("Browser does not support HTTP Request"); // Alert Them!
    28. return; // Returns.
    29. } // End If.
    30. htmlRequest.onreadystatechange = function(){
    31. if(htmlRequest.readyState == 4){
    32. document.getElementById("shoutarea").innerHTML = htmlRequest.responseText;
    33. var obj = document.getElementById('shoutarea');
    34. obj.scrollTop = obj.scrollHeight;
    35. }
    36. }
    37. htmlRequest.open("GET", "index.php?mode=outputinfo", true);
    38. htmlRequest.send(null);
    39. }
    40. showData();
    41. setInterval("showData()",1000);
    Alles anzeigen


    Und einmal für die Online Liste

    Quellcode

    1. function showsData() {
    2. var req;
    3. try {
    4. req = window.XMLHttpRequest?new XMLHttpRequest():
    5. new ActiveXObject("Microsoft.XMLHTTP");
    6. } catch (e) {
    7. try{
    8. req = new ActiveXObject("Microsoft.XMLHTTP");
    9. } catch (e){
    10. // Something went wrong
    11. alert("Your browser broke!");
    12. return false;
    13. }
    14. }
    15. req.onreadystatechange = function() {
    16. if ((req.readyState == 4) && (req.status == 200)) {
    17. document.getElementById("onlinearea").innerHTML = req.responseText;
    18. var obj = document.getElementById('onlinearea');
    19. obj.scrollTop = obj.scrollHeight;
    20. }
    21. }
    22. req.open("GET", "index.php?mode=outputinfos", true);
    23. req.send(null);
    24. }
    25. showsData();
    26. setInterval("showsData()",1000);
    Alles anzeigen


    Bei der Online Liste habe ich also diesmal

    Quellcode

    1. req = window.XMLHttpRequest?new XMLHttpRequest():
    2. new ActiveXObject("Microsoft.XMLHTTP");


    direkt in die Funktion geschrieben.

    Daraus schliesse ich das jede funktion ihren eigenen Ajax Request braucht. Liege ich da richtig?
  • Hi,

    zum Verständnis.
    Ein Request ist eine Anfrage an den Server. Zu dem Request gehört auch eine Response, die man optional verarbeiten kann. Für diesen Ablauf ist eine XML-HTTP Instanz nötig. Werden also 10 Anfrage gesendet, muss das Objekt 10mal instanziert werden.
    Die Funktion "ajaxFunction" die du nutzt, instanziert zu jedem Request das Objekt und gibt dieses zurück. Du musst diese Funktionalität also nicht in die anderen Funktionen reinkopieren, sondern kannst die Funktion für alle deine AjaxRequests nutzen.


    Quellcode

    1. function ajaxFunction() {
    2. var ajaxRequest; // The variable that makes Ajax possible!
    3. try{
    4. // Opera 8.0+, Firefox, Safari
    5. ajaxRequest = new XMLHttpRequest();
    6. } catch (e){
    7. // Internet Explorer Browsers
    8. try{
    9. ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    10. } catch (e) {
    11. try{
    12. ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
    13. } catch (e){
    14. // Something went wrong
    15. alert("Your browser broke!");
    16. return false;
    17. }
    18. }
    19. }
    20. if (htmlRequest==null){ // If it cannot create a new Xmlhttp object.
    21. alert ("Browser does not support HTTP Request"); // Alert Them!
    22. return false; // Returns.
    23. } // End If.
    24. return ajaxRequest;
    25. }
    26. function showData() {
    27. //htmlRequest = ajaxFunction();
    28. var htmlRequest = ajaxFunction();
    29. htmlRequest.onreadystatechange = function(){
    30. if(htmlRequest.readyState == 4){
    31. document.getElementById("shoutarea").innerHTML = htmlRequest.responseText;
    32. var obj = document.getElementById('shoutarea');
    33. obj.scrollTop = obj.scrollHeight;
    34. }
    35. }
    36. htmlRequest.open("GET", "index.php?mode=outputinfo", true);
    37. htmlRequest.send(null);
    38. }
    39. function showsData() {
    40. //htmlRequest = ajaxFunction();
    41. var htmlRequest= ajaxFunction();
    42. htmlRequest.onreadystatechange = function() {
    43. if ((htmlRequest.readyState == 4) && (htmlRequest.status == 200)) {
    44. document.getElementById("onlinearea").innerHTML = htmlRequest.responseText;
    45. var obj = document.getElementById('onlinearea');
    46. obj.scrollTop = obj.scrollHeight;
    47. }
    48. }
    49. htmlRequest.open("GET", "index.php?mode=outputinfos", true);
    50. htmlRequest.send(null);
    51. }
    52. showData();
    53. showsData();
    54. setInterval("showData()",1000);
    55. setInterval("showsData()",1000);
    Alles anzeigen