AJAX Script funktioniert nicht mit IE

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

  • AJAX Script funktioniert nicht mit IE

    hoi

    Also ich hab das Problemm das das Folgende Script nicht mit [coderwiki]Informationen/Internet-Explorer[/coderwiki] funktionirt :( was kann man da machen ??

    Quellcode

    1. var xmlHttp = false;
    2. try {
    3. xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    4. } catch(e) {
    5. try {
    6. xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    7. } catch(e) {
    8. xmlHttp = false;
    9. }
    10. }
    11. if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
    12. xmlHttp = new XMLHttpRequest();
    13. }
    14. loadData();
    15. setInterval("loadData()",500);
    16. function loadData()
    17. {
    18. if (xmlHttp) {
    19. xmlHttp.open('GET', 'getdata.php', true);
    20. xmlHttp.onreadystatechange = function () {
    21. if (xmlHttp.readyState == 4) {
    22. document.getElementById("content").innerHTML = xmlHttp.responseText;
    23. }
    24. };
    25. xmlHttp.send(null);
    26. }
    27. }
    Alles anzeigen
  • hi,
    was genau funktioniert denn nicht?

    hab das xmlHttp [coderwiki]Informationen/Objekt[/coderwiki] mal anders initialisiert und ein paar sachen hin- und herverschoben, so dass am codebau nichts geändert wurde

    Quellcode

    1. try {
    2. var xmlHttp = window.XMLHttpRequest?new XMLHttpRequest():
    3. new ActiveXObject("Microsoft.XMLHTTP");
    4. } catch(e) {
    5. var xmlHttp = false;
    6. }
    7. function loadData()
    8. {
    9. if (xmlHttp) {
    10. xmlHttp.onreadystatechange = function () {
    11. if (xmlHttp.readyState == 4)
    12. document.getElementById("content").innerHTML = xmlHttp.responseText;
    13. };
    14. xmlHttp.open('GET', 'getdata.php', true);
    15. xmlHttp.send(null);
    16. }
    17. }
    18. setInterval("loadData()",500);
    Alles anzeigen
  • hoi erstmal danke für deine schnelle antwort ist schonmal eine überlegung wert das [coderwiki]Informationen/Forum[/coderwiki] öfters zu Besuchen ;)


    hatte versehentlich unten was vergessen jetzt wird der code vieleicht auch verstentlicher... es ist ein reload mit ajax

    Hier nochmal der gesammte code ;)

    Quellcode

    1. var xmlHttp = false;
    2. try {
    3. xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    4. } catch(e) {
    5. try {
    6. xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    7. } catch(e) {
    8. xmlHttp = false;
    9. }
    10. }
    11. if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
    12. xmlHttp = new XMLHttpRequest();
    13. }
    14. loadData();
    15. setInterval("loadData()",500);
    16. function loadData()
    17. {
    18. if (xmlHttp) {
    19. xmlHttp.open('GET', 'getdata.php', true);
    20. xmlHttp.onreadystatechange = function () {
    21. if (xmlHttp.readyState == 4) {
    22. document.getElementById("content").innerHTML = xmlHttp.responseText;
    23. }
    24. };
    25. xmlHttp.send(null);
    26. }
    27. }
    Alles anzeigen
  • ich würd sagen, dein IE kann kein AJAX

    Quellcode

    1. <?if(isset($_GET['x'])) die(''.rand(1,1000)); ?>
    2. <html>
    3. <head>
    4. <script type="text/javascript">
    5. //<![CDATA
    6. try {
    7. var xmlHttp = window.XMLHttpRequest?new XMLHttpRequest():
    8. new ActiveXObject("Microsoft.XMLHTTP");
    9. } catch(e) {
    10. var xmlHttp = false;
    11. }
    12. function loadData()
    13. {
    14. if (xmlHttp) {
    15. xmlHttp.onreadystatechange = function () {
    16. if (xmlHttp.readyState == 4)
    17. document.getElementById("content").innerHTML = xmlHttp.responseText;
    18. };
    19. xmlHttp.open('GET', 'ajax.php?x='+new Date().getMilliseconds(), true);
    20. xmlHttp.send(null);
    21. }
    22. }
    23. //]]>
    24. </script>
    25. </head>
    26. <body onload="loadData()">
    27. <div id="content"></div>
    28. </body>
    29. </html>
    Alles anzeigen
  • der IE cached ein bisschen anders.
    Hänge mal einen beliebigen Parameter mit new Date().getMilliseconds() an deine URL hinten dran.

    Und benenne deine ausführende Datei ajax.php - das habe ich oben vergessen.
    Und weils schöner ist, habe ich das Laden noch in die onload Funktion geschoben. Wenn das nicht funktioniert, dann weiß ich auch nicht weiter.
  • Absolut richtig. Der IE verhält sich beim cache anders.

    Quellcode

    1. xmlHttp.open('GET', 'getdata.php', true);

    Das funktioniert nicht im IE weil die Seite vom cache geholt wird.

    Man muss einen zusätzlichen Parameter für den IE dazu nehmen damit der cache im IE umgangen wird.
    Z.B. so.

    Quellcode

    1. xmlHttp.open('GET', 'getdata.php?id='+Math.round(Math.random()*100000+1),true);

    oder so

    Quellcode

    1. xmlHttp.open('GET', 'getdata.php?x='+new Date().getMilliseconds(), true);
  • Also ich hab genau das gleische Problem. Im IE geht es nicht, aber im Firefox schon.

    Hier mal mein Script:

    Quellcode

    1. <!--
    2. var req;
    3. try {
    4. req = window.XMLHttpRequest?new XMLHttpRequest():
    5. new ActiveXObject("Microsoft.XMLHTTP");
    6. } catch (e) {
    7. //Kein AJAX Support
    8. }
    9. function login (nick, pass) {
    10. document.getElementById('login_btn').innerHTML = "<img src='gfx/load.gif'>";
    11. req = window.XMLHttpRequest?new XMLHttpRequest():
    12. new ActiveXObject("Microsoft.XMLHTTP");
    13. req.onreadystatechange = function() {
    14. if ((req.readyState == 4) && (req.status == 200)) {
    15. document.getElementById('login_table').innerHTML = req.responseText;
    16. }
    17. }
    18. req.open('POST', 'login.php');
    19. req.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
    20. req.send('nick='+nick+'&pass='+pass);
    21. return false;
    22. }
    23. //-->
    Alles anzeigen