greetings gudii9, , I will comment here, you are just learning how to use javascript, and the javascript DOM function-method of getElementById( ) is a very very Necessary function to use and understand !
as you can see the w3schools tutorial page for DOM methods at -http://www.w3schools.com/js/js_htmldom_methods.asp

here is some Page code that uses the getElementById( ) to change FOUR DOM elements on the HTML page -

If you are learning Javascript, it is usually better to use a function-method like document.getElementById( ) on several Different elements in some different ways ( innerHTML, style ) to see how and why it works.

ALSO, the use of the javascript AJAX -
new XMLHttpRequest();
is a MUCH MORE complicated set of operations involving Browser and Server code and operations, this XMLHttpRequest(); if really NOT for javascript beginners, who try and do "copy and Paste" code, without understanding the complex set of operations needed to do javascript AJAX exchanges with success in browser "AJAX interface" display.

my guess is that you have IIS installed and are running the site through there.

document.getElementById

is more like
System.out.println in the java language

no, document.getElementById gets a reference to any control within the DOM (or page, to simplify things). if you wanted to get a reference to a field in your form that had an ID of "email" you would do:

? ? ? The Page code I posted that you ran comment ID: 41826566 above is NOT using any AJAX, to use AJAX you must call this -
new XMLHttpRequest();

which I did NOT do. Because, you are just learning javascript, and the complicated operations of the XMLHttpRequest() will require you to know much more about javascript than you now know.

In that page script, I was just trying to get you to USE the -
document.getElementById("id");
to show you HOW that getElementById( ) could be used on a page with javascript. I had hoped that you would CHANGE that page and add a <div> or a paragraph <p> with a different ID -
<div id="newDiv">

and then place your own javascript code in the page to access that <div> with the -
getElementById( )
and then change the "Content" inside that <div> with the -
.innerHTML
property

In javascript you must know how and why to use the getElementById( ) before you can try the more advanced and difficult XMLHttpRequest()

and then place that text file in the same folder that you have the html file with the code you have presented here, with the -
new XMLHttpRequest();

javascript in it.

if you are learning about the AJAX and the XMLHttpRequest() you should start with an XMLHttpRequest() that does NOT use any JSON, then when you learn more about the new XMLHttpRequest() , you can change it to do more complex display using the JSON

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

The answer is NO , it does not create any file for any reason at any time. The text file "myTutorials.txt" is NOT created by the XMLHttpRequest() javascript code, , as far as I know the XMLHttpRequest() can NOT create a "FILE" anywhere. As I said you may need to learn more about javascript and the AJAX operations that are used for the XMLHttpRequest() to know what to do and how to do it in javascript

? ? ?
I am trying to help you with this, but in your last comment you have just RE POSTED the same exact code that you have posted BEFORE, no changes at all. . You did not do anything but copy and paste the SAME code, , and you say you got the exact SAME results (one seems to work ,and one seems not to work) that you said in comments you have here before, same code and results. You need to CHANGE this code, by your own understandings of the javascript operations, you can not learn anything by just doing the "COPY and PASTE", without trying to find out what the javascript functions and elements are doing. and how you can change them to have different page display and results.

If you have questions about what the javascript variables, functions, arrays, objects, and methods are for, or what they do or how to change them , then ask questions about that, ask about what you do not understand/ I do not know that to say here you help you, if all you do is paste code.

Just some information about the javascript XMLHttpRequest() object, , it is likely that this XMLHttpRequest() will NOT work on the browser computer file system, the "localhost" as you term it. The XMLHttpRequest() operations usually REQUIRE that the XMLHttpRequest() .send( ) method is to a URL HTTP server address, in the SAME domain name that the html file has come from. So it is likely that this will not work UNTIL you have a remote WEB SERVER with your test.html file and the myTutorials.txt file On that server file system, and you use the remote server for all XMLHttpRequest() transfers.

Then it'll work fine as long it's in the same domain (web root). If index. asp is being opened through the file system it will not work. It doesn't matter if it's a remote web server or local one, as long as the relative format is used it'll work

Ok so you're NOT using a web server, so as Slick mentioned earlier, this won't work. You need to set up IIS on your system, assuming you're running Windows, all you should need to do is do Add/Remove options and select it there. A quick Google search will explain it in more details.

@gudii9
I have told you before that u are doing things in code work that you do not have the knowledge or experience for. If you are a JAVA developer, than get a REMOTE SERVER HOST that is a JAVA, with Tomcat LAMP, and then to the extreamly simple XMLHttpRequest() example that you gave as a LEARNING code here -http://www.w3schools.com/js/js_json_http.asp
using a remote server. The XMLHttpRequest() is ONLY used for dynamic returns (usually from a database) for PAGE user interactive activities. You are just going around in circles, with your comments here. Please ask about What you are trying to LEARN here, you seem to know little about javascript, and installing a IIS on your machine will probably not teach you what you need to learn. So I ask you now.

BUT in javascript any external connections like AJAX XMLHttpRequest() or the newer WebSocket( ) WILL NOT WORK in a browser, because the XMLHttpRequest() requests a connection to the ajax URL which does not exist in a "File System" environment. So to have ANY javascript with the XMLHttpRequest() you MUST get a windows operating system server "SET UP" to handle web connection request that are use in the XMLHttpRequest() operation.

= = = = = = = = = = = = = = = = =

If you are trying to learn JavaScript Object Notation JSON, then you should be creating Arrays and Objects in javascript using the symbols for JSON containers, for arrays [ ] , , , , , and for objects { } . . . .

BUT in javascript any external connections like AJAX XMLHttpRequest() or the newer WebSocket( ) WILL NOT WORK in a browser, because the XMLHttpRequest() requests a connection to the ajax URL which does not exist in a "File System" environment. So to have ANY javascript with the XMLHttpRequest() you MUST get a windows operating system server "SET UP" to handle web connection request that are use in the XMLHttpRequest() operation.

any good end to end examples, links on this?(prefrably using java web servers like tomcat etc rather than .Net engines(actually either is fine)

@gudii9 , , , I have never done a JAVA Apache Tomcat as a local server on a windows machine. I have done a LAMP (for PHP) as a local server on a windows machine. You may should ask this question in the experts exchange category of JAVA, to have people that have actually done this , Apache Tomcat as a local server , to help you with suggestions.

0

Featured Post

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Introduction
A frequently asked question goes something like this: "I am running a long process in the background and I want to alert my client when the process finishes. How can I send a message to the browser?" Unfortunately, the short answer …

Introduction
JSON is an acronym for JavaScript Object Notation. It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner. Similar in concept to XML, but more e…

The viewer will learn the basics of jQuery, including how to invoke it on a web page.
Reference your jQuery libraries: (CODE)
Include your new external js/jQuery file: (CODE)
Write your first lines of code to setup your site for jQuery.: (CODE)