Wednesday, April 18, 2012

Learn AJAX in 20 minutes

AJAX stands for Asynchronous JAvascript and Xml. The main idea is that a web page can use AJAX to send requests (using Javascript) to a web server and then update parts of the page (which are specified using Javascript) according to the web server's response (which could run any type of script, e.g., PHP).

Here's the detailed sequence of steps typically found in an AJAX-enabled web page:

  1. [@web browser] Some event occurs (e.g., onload or after clicking something)
  2. [@web browser] A Javascript function is called 
  3. [@web browser] An XMLHttpRequest Object is created
  4. [@web browser] HttpRequest sent to web server
  5. [@web server] HttpRequest processed, typically by a PHP script
  6. [@web server] A response is generated (e.g., by looking up a database entry)
  7. [@web server] Response is sent back to browser
  8. [@web browser] Process the returned data using Javascript (data could be text, html, or xml)
  9. [@web browser] Update parts of web page, specified by Javascript (e.g., using elementID)


  • hello1.html -- "Hello World" example, where after clicking the "Change Content" button, a request is sent to the web server for file hello_ajax.txt which is retrieved by the browser and used to change the content of the page.
  • hello2.html --  same with the previous example, but with the addition of a timestamp, computed locally by Javascript at the browser.
  • hello3.html --  same with the previous example, but now instead of a static file read from the web server, the content is generated by calling hello_ajax.php (source -- run) which computes the date and picks a random pair of words to show.
  • hello4.html --  same with the previous example, but now the PHP script at the web server hello_ajax_d.php (source -- run) includes a time delay of 2 seconds. This is used to demonstrate the asynchronous nature of AJAX. Notice the difference of the two timestamps displayed.
  • suggest.html -- generate suggestions for first names (that have the same prefix as what has been typed), after one or more letters are typed. Relies on gethint.php 
  • suggest2.html -- generate suggestions for first names (that contain these letters), after one or more letters are typed. Relies on gethint2.php

More information:

    Sunday, April 15, 2012

    Clarifications to term project

    Please see the comments of this post for important clarifications to the term project.

    Clarifications to Assignment #4

    Please see the comments of this post for important clarifications to Assignment #4.

    Term Project released

    The term project has been released. It will be due on Thursday, April 26th (at midnight). We will do demos all day, Friday, April 27th (a sign-up sheet will be provided). If you are working in groups, we need to create new databases for you, so that your personal username/password are not shared.

    Friday, April 13, 2012

    Assignment #4 posted

    Assignment #4 on javascript has been posted. It is due on April 24th. This assignment is optional. If you submit it, we will count the best three assignment grades for your assignment grade.

    Update on Final Exam / Grading Policy

    As we have discussed in class and via email, there will not be a final exam, but instead we will give more weight to the term project. The updated grading policy is as follows:
    • Assignments: 35% (was 30%)
    • Term project + demo: 30% (was 15%)
    • Class participation: 5% (was 5%)
    • Midterm exam: 30% (was 25%)
    • Final exam: 0% (was 25%)
    Also, the fourth assignment is an optional one. If you submit it, we will use the best three grades out of the four assignments to determine your assignments grade.

    Wednesday, April 11, 2012