This requires a very slight amount of multi-browser scripting...
I found this example at http://ajaxpatterns.org/XMLHttpRequest_Call
################################################
function createXMLHttpRequest() {
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
try { return new XMLHttpRequest(); } catch(e) {}
alert("XMLHttpRequest not supported");
return null;
}
var xhReq = createXMLHttpRequest();
#################################################
#################################################
xhReq.open("GET", "showmelove.html", true);
#################################################
#################################################
function iAmBack(){
alert("The server called back")
}
xhReq.onreadystatechange = iAmBack;
##################################################
##################################################
xhReq.send(null);
##################################################
Try it out by copying the following two files and putting them on some server that you can access with a web browser... You can even put them in a local directory and access them via your web browser, but you will need to click "Allow Blocked Content" in your browser
#################PUTTING IT ALL TOGETHOR FILE 1##################
NOTE: name this file - index.html
<script language="javascript">
function createXMLHttpRequest() {
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
try { return new XMLHttpRequest(); } catch(e) {}
alert("XMLHttpRequest not supported");
return null;
}
var xhReq = createXMLHttpRequest(); <!--- Here's where we create the object -->
function iAmBack(){ <!-- Here is the method that is called when we're done -->
if (xhReq.readyState != 4) { return; }
var serverResponse = xhReq.responseText;
alert(serverResponse) <!-- Here is where we shout out what we got from the server >
}
function showMeSomeServerLove(){ <!--- Here's where all of the magic happens -->
xhReq.open("GET", "showmelove.html", true);
xhReq.onreadystatechange = iAmBack;
xhReq.send(null);
}
<a onclick="showMeSomeServerLove()">Click For Love</a>
#################PUTTING IT ALL TOGETHOR FILE 2##################
How do I love thee? Let me count the ways.
I love thee to the depth and breadth and height
My soul can reach, when feeling out of sight
For the ends of Being and ideal Grace.
I love thee to the level of everyday's
Most quiet need, by sun and candle-light.
I love thee freely, as men strive for Right;
I love thee purely, as they turn from Praise.
I love thee with the passion put to use
In my old griefs, and with my childhood's faith.
I love thee with a love I seemed to lose
With my lost saints!---I love thee with the breath,
Smiles, tears, of all my life!---and, if God choose,
I shall but love thee better after death.
-- Elizabeth Barrett Browning
I am dedicating this page to my wonderful wife Melissa Trujillo.
I (Marty Trujillo) built this page because am sick and tired of having to reaquaint myself with hand rolling AJAX everytime I need to use it [AJAX]. I don't need it often enough to cement it into my brain and I have a terrible memory. If someone stumbles onto this page and finds it useful, then cool. You can repay me by putting something useful or interesting on the internet.
If this doesn't make sense to you or you want more information then I suggest checking out AJAX on the wikipedia. If you go to Yahoo and enter the search terms AJAX Wiki you should find it pretty quickly.
Good luck... Click For Love