Code for APP

From rbachwiki
Revision as of 14:11, 16 November 2016 by Bacchas (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Text file is created with text

Outwter Plastics

HTML code

 <body>
    <button id="btn" type="">Click Me</button>
<div id="output">
    
</div>

    <script src="script.js"> </script>
    </body>

Java Script Code

(function() {

    document.querySelector('#btn').addEventListener('click', showData);

    function showData() {

        var httpRequest = new XMLHttpRequest();
        httpRequest.onreadystatechange = function() {

            if (this.readyState === 4 && this.status === 200) {
                console.log(httpRequest.responseText);
                document.querySelector('#output').innerHTML = httpRequest.responseText;
            } else {
                console.log('Not ready yet:');
            }

        };

        httpRequest.open('GET', 'test.txt', true);
        httpRequest.send();

    }

})();

Back to Previous Page