How to fetch information from a normal file with AJAX?

0 votes
Ethan Karla asked 19-Aug-2021 in programming by Ethan Karla

How to fetch information from a normal file with AJAX?

1 Answer

0 votes
Ravi Vishwakarma answered 29 days ago by Ravi Vishwakarma
<!doctype html>

<html lang='en'>
    <!-- Required meta tags -->
    <meta charset='utf-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1'>
    <!-- Bootstrap CSS -->
    <link href='' rel='stylesheet' integrity='sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC' crossorigin='anonymous'>
    <title>Ajax Example</title>
    <div class='container mt-3'>
        <h1 class='text-center'>Ajax Example </h1>
        <button type='button' onclick='loadResponseText()' class='btn btn-primary my-3'>Click me for see the details of selected page</button>
        <h3 class='text-danger '>See details of of page</h3>
        <p class='text-primary'>Whole information of page <span id='details' class='text-muted'></span></p>
        <p id='loadAjaxInText' class='text-center'>call ajax without reload the page</p>
        function loadResponseText() {
            // creating instance of XMLHttpRequest()
            var xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function () {
                if (this.readyState == 4 && this.status == 200) {
                    // call responseXML
                    document.getElementById('details').innerHTML = this.getAllResponseHeaders();
                    document.getElementById('loadAjaxInText').innerHTML = this.responseText;
  'GET', 'ajax_demo.txt', true);
    <script src='' integrity='sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM' crossorigin='anonymous'></script>


<h1 class='alert alert-primary'>AJAX</h1>

<p class='text-danger'>AJAX is not a programming language.</p>
<p>AJAX is a technique for accessing web servers from a web page.</p>
<p class='bg-danger text-white'>AJAX stands for Asynchronous JavaScript And XML.</p>


How to fetch information from a normal file with AJAX?