Dr. Mark Humphrys

School of Computing. Dublin City University.

Home      Blog      Teaching      Research      Contact

Search:

CA216      CA249      CA318

CA400      CA651      CA668


Javascript Ajax



Ajax is not about XML



Reference





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

JS

Minimal size demo of calling a server-side program HTML

JS

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

On Internet since 1987.