Ajax Tests

Note: if you are testing in Netscape Navigator or Firefox for Firefox <= 1.0 you cannot run these tests locally on your computer. You must run them from http://forkjavascript.org/ajax/tests . This is because these old browsers will not allow POST requests to localhost.

Examples

  1. isSupported
  2. Simple
  3. Error
  4. Form
  5. Throbber
  6. Polling
  7. Leak
  8. Queue
  9. Abort
  10. Abort Leak
  11. Timeout
  12. Timeout Leak

isSupported

GO!

Simple

new FORK.Ajax('GET', '/ajax/simple',
                  {
                    onSuccess: function(o) {
                                 document.simpleForm.pagesource.value = o.responseText;
                               }
                  }
                 );

GO!

Error

new FORK.Ajax('GET',
                  '/ajax/missing',
                  {
                    onSuccess: function(o) {
                                 alert("success");
                               },
                    onComplete: function(o) {
                                  alert("Error!\nStatus = " +
                                        o.status +
                                        "\nContents = " + 
                                        o.responseText);
                                }
                  }
                 );

Go!

Form

new FORK.Ajax('POST', '/ajax/form',
                  {
                   form: "exampleForm",
                   onSuccess: function(o) {alert("success");},
                   onComplete: function(o) {alert("failure");}
                  }
                 );
value1
value2
a b c
value3
yes
value4
value5
value6
(hidden input with name=value6, value=test)
value7
(file inputs will not get submitted)
value8
value9

Find the form by name and serialize it.

Throbber

document.getElementById('throbberGif').style.visibility = 'visible';
    
new FORK.Ajax('GET', '/ajax/throbber',
                  {
                   before: function(o) {
                             document.getElementById("throbberGif").style.visibility =
                              "hidden";
                           }
                  }
                 );

Go!

Polling

This example polls 10 times. Each poll starts one second after the last one finished.

Go!

Polls:

Leak

Watch in Windows' Task Manager's System Performance Tab for memory use. The server returns a 10 MB file for each request and during the polling the memory use should show garbage collection at times.

new FORK.Ajax('GET', '/ajax/leak');

Disabled on public site to conserve bandwidth

Leak Polls:

Queue

Press the Go link many times and wait for the numbers to disappear. Eventhough the server takes a long time to respond, the requests wait in line. If your server can only handle one request at a time then the numbers should disappear at roughly even intervals. If your server can process more than one request simultaneously you may see the numbers disappear at uneven intervals which is good. The Fork site currently can handle two processes and so the numbers disappear roughly in pairs.

new FORK.Ajax('GET', '/ajax/leak');

Go!

Abort

Sever sleeps for 5 seconds but request is aborted after one.

new FORK.Ajax('GET', '/ajax/sleep_long',
                    {onComplete: function(o){
                                   alert("server responded");
                                 }}
                   );
  

Go!

Abort Leak

TODO need a test for abort memory leak in IE

Timeout

The server takes too long to respond and the Ajax request times out after two seconds.

new FORK.Ajax('GET', '/ajax/sleep_long',
                    {onComplete: function(o){
                                   alert("server responded");
                                 },
                     timeout: 2000,
                     onTimeout: function(o) { 
                                  alert('timed out');}
                                }
                   );
  

Go!

Timeout Leak

TODO need a test for timeout memory leak in IE