How to Program in Ajax

Prepare a picture for writing an Ajax program., Open any text editor., Create a new file in the text editor., Save the file as a text document with the name of “ajax-data.txt.” Actually, you can name the file whatever you want but make sure you...

22 Steps 2 min read Advanced

Step-by-Step Guide

  1. Step 1: Prepare a picture for writing an Ajax program.

    Save the picture in the same folder where you will save your html and text files displaying the Ajax program.

    In this article, “ProgramInAjax” directory is set up inside the “wamp” folder under the “www” directory where you installed WampServer. , Notepad++ is used as the text editor in this article. , Type the following: <h2>Oh oh! Where did the yellow flower go?</h2> You may type whatever you want inside the html tag <h2></h2> here. ,, This file is for an HTML file to view the Ajax program in a Web browser. ,, Click the save button on the menu bar.

    A “Save As” box is open.

    Enter a name for your document.

    In this article, the name of the file is “index.” , At the “Save as type” field, click the drop down arrow to choose the file extension. , Click save after selecting the “html.” , Open the webpage in a web browser.

    Go to “Run” on the top menu bar.

    Click it and select “Launch in Chrome” or any browser being installed in your system.

    Google Chrome is used for the testing in this article.

    You may have some other browsers installed within Notepad++.

    You can select your favorite browser.

    Another option, you can click the WampServer icon at the taskbars at the bottom of the screen and select “Localhost.” You should see your directory there and click the index file. ,, Your webpage should be refreshed with the information that you entered into the text file at the beginning.

    The flower and the header should be replaced with the new header called “Oh oh! Where did the yellow flower go?”
  2. Step 2: Open any text editor.

  3. Step 3: Create a new file in the text editor.

  4. Step 4: Save the file as a text document with the name of “ajax-data.txt.” Actually

  5. Step 5: you can name the file whatever you want but make sure you enter the same file name to the coding in this line: xmlhttp.open("GET"

  6. Step 6: "ajax-data.txt"

  7. Step 7: true); However

  8. Step 8: the HTML tag <h2></h2> is used for the header so that it looks bigger and more invisible.

  9. Step 9: Create a new file for a webpage.

  10. Step 10: Copy the following code: <!DOCTYPE html> <html> <head> <title>My First Ajax Program by Me</title> <!--Put the Ajax code below.--> <script> function loadXMLDoc() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+

  11. Step 11: Firefox

  12. Step 12: Chrome

  13. Step 13: Safari xmlhttp = new XMLHttpRequest(); } else {// code for IE6

  14. Step 14: IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById("myImage").innerHTML = xmlhttp.responseText; } } xmlhttp.open("GET"

  15. Step 15: "ajax-data.txt"

  16. Step 16: true); xmlhttp.send(); } </script><!--End of the script--> </head> <body style="text-align: center;"> <!--An image goes here to test the Ajax program.--> <div id="myImage"> <h2>Click the button below to make the flower disappear.</h2> <img src="MyPicture.png" width="500px" height="300px" title="Yellow Flower" alt="an image of a yellow flower"/> </div> <br/> <!--A button goes here--> <button type="button" onclick="loadXMLDoc()">Click here to make the picture disappear!</button> </body> </html>

  17. Step 17: Save the file.

  18. Step 18: Click the drop down arrow to choose the file extension.

  19. Step 19: Select “Hyper Text Markup Language file.” Make sure that it has “html” inside the parenthesis.

  20. Step 20: Test the HTML file in a Web browser.

  21. Step 21: Click the button below the picture to test the script.

  22. Step 22: Your final webpage.

Detailed Guide

Save the picture in the same folder where you will save your html and text files displaying the Ajax program.

In this article, “ProgramInAjax” directory is set up inside the “wamp” folder under the “www” directory where you installed WampServer. , Notepad++ is used as the text editor in this article. , Type the following: <h2>Oh oh! Where did the yellow flower go?</h2> You may type whatever you want inside the html tag <h2></h2> here. ,, This file is for an HTML file to view the Ajax program in a Web browser. ,, Click the save button on the menu bar.

A “Save As” box is open.

Enter a name for your document.

In this article, the name of the file is “index.” , At the “Save as type” field, click the drop down arrow to choose the file extension. , Click save after selecting the “html.” , Open the webpage in a web browser.

Go to “Run” on the top menu bar.

Click it and select “Launch in Chrome” or any browser being installed in your system.

Google Chrome is used for the testing in this article.

You may have some other browsers installed within Notepad++.

You can select your favorite browser.

Another option, you can click the WampServer icon at the taskbars at the bottom of the screen and select “Localhost.” You should see your directory there and click the index file. ,, Your webpage should be refreshed with the information that you entered into the text file at the beginning.

The flower and the header should be replaced with the new header called “Oh oh! Where did the yellow flower go?”

About the Author

A

Ashley Phillips

A seasoned expert in lifestyle and practical guides, Ashley Phillips combines 4 years of experience with a passion for teaching. Ashley's guides are known for their clarity and practical value.

152 articles
View all articles

Rate This Guide

--
Loading...
5
0
4
0
3
0
2
0
1
0

How helpful was this guide? Click to rate: