show loading status with ajax call
<p>I'm looking for a JavaScript solution to show some sort of status while an ajax request is taking place. I tried <code>document.getElementById("status").innerHTML = "&lt;h2&gt;Loading....&lt;/h2&gt;";</code> but that didn't work. Any ideas?</p>

<pre><code>function codesDelete(id) {
    var ajax;
    if (window.XMLHttpRequest) {
        ajax = new XMLHttpRequest();
    } else {
        ajax = new ActiveXObject("Microsoft.XMLHTTP");
    }

    ajax.onreadystatechange = function() {
        if (ajax.readyState === 4 &amp;&amp; ajax.status === 200) {
            document.getElementById("status").innerHTML = "&lt;h2&gt;Data Deleted!&lt;/h2&gt;";
        }
    }

    // this is what i tried
    document.getElementById("status").innerHTML = "&lt;h2&gt;Loading....&lt;/h2&gt;";


    ajax.open("GET", "code.php?id=" + id, true);
    ajax.send();

    setTimeout(function() {
        document.getElementById("status").style.display = "none";
    }, 3000);
}
</code></pre>
