Assignment

The JavaScript in Figure 14-4 used Ajax to read the contents of a file called sample.txt, but it did not display the contents of the file. Your assignment is to write a page that asks for a file to read in, and then displays the contents of that file in a div. Figure 14-7 depicts how a solution might look after a user entered sample.txt into the text field and clicked the Get the File button. Remember, the file that Ajax reads must live in the same directory as one that contains the Ajax code.

Displaying the contents of a file

Figure 14-7. Displaying the contents of a file

Get The Book of JavaScript, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.