Dr. Mark Humphrys

School of Computing. Dublin City University.

Home      Blog      Teaching      Research      Contact

My big idea: Ancient Brain


CA216      CA249      CA318

CA400      CA651      CA668

Javascript Ajax

Ajax is not about XML


Javascript Ajax demos

I remove the header and footer to make it easier to View Source.

Demo HTML (View Source) Javascript (View Source)
Javascript Ajax demo HTML JS
Javascript Ajax demo - calling a server-side program HTML


Minimal size demo of calling a server-side program HTML


Javascript Ajax - Parsing XML on the client side HTML JS

Asynchronous programming

Ajax takes some getting used to, because it is asynchronous.
You fire off a HTTP request. And then your code carries on.
At some future point the HTTP request returns.
When you make the request, you include the future function to call.

So you can't say:

string x = makeRequest(url);  // get back string
// do stuff with x ...
Instead you do:
makeRequest(url, fn); 
// .. don't do anything with x yet

function fn()	// called when request returns in future 
 string x =  // .. get return value 
 // now can do stuff with x ...

// and you may need multiple lines like this throughout the code:

if ( x ) .....

// there is uncertainty in code if x exists yet or not

XHR (original) - Same origin policy

XHR2 - Cross-origin Ajax

Feeds      w2mind.org      ancientbrain.com

On the Internet since 1987.