javascript - XMLHttpRequest not working - no errors -


I am trying to do this simple request but I am not very fortunate. I have a "test.txt" file in the server file, as is my HTML file with the script below.

I have seen the file with the same result in Chrome, Firefox and IE11. I can only see the text "Initial text in the html page" from the html page. No error and text from my test.txt file is showing.

Can anyone tell me what's the problem with my code?

  & lt ;! DOCTYPE html & gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; Script type = "text / javascript" & gt; Var xmlHttp = createXmlHttpRequestObject (); Create function xmlHttpRequestObject () {var xmlHttp if (window.XMLHttpRequest) {xmlHttp = new XMLHttpRequest (); } And {xmlHttp = New ActiveXObject ("Microsoft.XMLHTTP"); } Return xmlHttp:} function process () {if (xmlHttp) {try {xmlHttp.open ("GET", "test.txt", true); XmlHttp.onreadystatechange = handleServerResponse; XmlHttp.send (zero); } Catch (e) {warning (e.toString ()); }}} Function Handlers Server Response () {output = document.getElementById ('output'); If (xmlHttp.readyState == 1) {output.innerHTML + = "Status1: The server connection is established & lt; br / & gt;" } And if (xmlHttp.readyState == 2) {output.innerHTML + "Status2: Request Received 
Output.inner HTML + = Text; } Catch (e) {warning (e.toString ()); }} And {warning (xmlHttp.statusText); }} & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body Onload = "Process ()" & gt; Initial text in the Html page .. & lt; Br> & Lt; Br> & Lt; Div id = "output" & gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt;

OK, I understood it ....

It was a Typo and a Omison Returns xmlHttp: - & gt; should be there ; Instead

and "and" forgot

  else (xmlHttp.readyState == 4) {-> Second should be (xmlHttp.readyState == 4) {   

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -