I have js code as well as *.txt file with some text that I want to load to the page.
JS Code:
(function () {
var link = document.getElementsByTagName("a")[0];
link.onclick = function () {
var xhr = new XmlHttpRequest();
xhr.onreadystatechange = function () {
if ((xhr.readyState == 4) && (xhr.status == 200 || xhr.status == 304)) {
xhr.responseText;
var body = document.getElementsByTagName("body")[0];
var p = document.createElement("p");
var pText = document.createTextNode(xhr.responseText);
p.appendChild(pText);
body.appendChild(p);
}
};
xhr.open("Get", "ajax.txt", true);
hxr.send(null);
return false;
};
})();
HTML Code:
<body>
<h1>AjaxTest</h1>
<a href="ajax.txt">Load the text from file</a>
<script src="main.js">
</script>
Everything should work. However ReSharper underlines XmlHttpRequest(); and says Use of an implicitly declared global variable" and for this xhr.responseText; it says - Expression statement is not assignment of call. What is the problem?