简体   繁体   中英

Javascript Ajax: never ending loading spinner

I am facing a behaviour, I don't understand. In Firefox 54.0 I have implemented a pretty simple Javascript to make an Ajax-request.

The Firefox works well, but doesn't stop to show the spinning wheel in the tab. This seems to be not a real problem but I always get asked, why. Does anyone know the reason? Chrome dosn't show that problem, only Firefox.

Regards

<!doctype html>
<html>
<head>  
<title>Ajax</title>
<meta charset="utf-8">

<script type="text/javascript"> var meinRequest = new XMLHttpRequest();

    meinRequest.open ( 'GET', 'daten.txt', true );

    meinRequest.onreadystatechange = function(){
        if ( meinRequest.readyState == 4 && meinRequest.status == 200 ){
            document.write ( meinRequest.responseText );
        } else if ( meinRequest.readyState == 4 ){
            console.log ( 'Fehler ' + meinRequest.status );
        }           
    }

    meinRequest.send();

</script>
</head>
<body>
</body>

</html>

Okay, just found the answer myself:

The document.write() forces firefox to expect more. I simple replaced it with

document.body.innerHTML += ( meinRequest.responseText );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM