Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Nachladen mit AJAX

Empfohlene Antworten

Veröffentlicht

Hi,

ich versuche mit AJAX eine XML-Datei nachzuladen. Dazu verwende ich den folgenden Code:


var ajax = null;


try {

    ajax = new ActiveXObject("Microsoft.XMLHTTP");

} catch (Exception) {

    try {

        ajax = new ActiveXObject("MSXML2.XMLHTTP");

    } catch (Exception) {

        try {

            ajax = new XMLHttpRequest();

        } catch (Exception) {

            location.href = "http://www.google.de";

        }  

    }

}


function reload() {

    try {    

        ajax.open("GET", "http://www.martinlange.eu/rss/index.php", true);

        ajax.onreadystatechange = handleResponse;      

        ajax.send(null);

    } catch (error) {

        document.write(error.toString());

    }

}


function handleResponse() {


    document.write("readyState"  +  ajax.readyState);


    if (ajax.readyState == 4) {

        document.write(ajax.responseText);

    }

}

Sollte eigentlich ein leicht abgewandeltes Beispiel sein. Mein Problem ist, dass ich beim readyState nicht über die 1 (= loading) hinaus komme. Auch wenn ich 5 Minuten warte. Weiß irgendjemand, was ich da falsch gemacht habe.

Auf den ersten Blick sieht es OK aus, auch wenn ich das Erstellen des HTTPRequest Objekts anders gemacht hatte.

Was sagt LiveHTTPHeaders (für Firefox) denn? Wird der Request abgeschickt und wie sieht er aus?

LiveHTTPHeaders-Antwort:


http://lange/rss/index.php


GET /rss/index.php HTTP/1.1

Host: lange

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6

Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3

Accept-Encoding: gzip,deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive: 300

Connection: keep-alive


HTTP/1.x 200 OK

Server: Microsoft-IIS/5.1

Date: Wed, 23 Aug 2006 13:31:29 GMT

X-Powered-By: ASP.NET, PHP/5.1.4

Connection: close

Content-Type: text/xml

Hier mal die ausgabe, wenn ich die Seite im ersten Beitrag aufrufe:

http://www.martinlange.eu/rss/index.php

GET /rss/index.php HTTP/1.1

Host: www.martinlange.eu

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6

Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3

Accept-Encoding: gzip,deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive: 300

Proxy-Connection: keep-alive

HTTP/1.x 200 OK

Date: Wed, 23 Aug 2006 14:20:42 GMT

Server: Apache/2.0.54 (Debian GNU/Linux) PHP/5.1.5 DAV/2

X-Powered-By: PHP/5.1.5

Content-Length: 7770

Content-Type: text/xml

X-Cache: MISS from Proxy.Server.tld

Proxy-Connection: keep-alive

Was mir da auffällt ist die fehlende Content-Length bei dir. Scheinbar sendet der Server bei dir zwar ein OK, aber keinen Inhalt. Sagt das ErrorLog da vielleicht etwas?

Oder leer mal den Browsercache.

Hab inzwischen die handleResponse geändert in:


function handleResponse() {

    if( 4 == ajax.readyState ) {

        if( 200 != ajax.status ) {

            alert( "Fehler " + ajax.status + ": " + ajax.statusText );

        } else {

            alert( ajax.responseText );

        }

    }

}

und oh Wunder, es läuft. Kam anscheinend irgendwie mit dem document.write nicht zurecht.

BTW: Wo finde ich die Option für Firefox, dass ich auch von fremden Seiten nachladen kann?

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.