topical media & game development
lib-ajax-example-page.htm / htm
<head>
<script type="text/javascript" language="javascript">
replace(s)
function ReplaceElementID(url,id)
{
var httpRequest;
if (window.XMLHttpRequest)
{
try { httpRequest = new XMLHttpRequest(); }
catch(e) {}
}
else if (window.ActiveXObject)
{
try { httpRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
catch(e)
{
try { httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); }
catch(e) {}
}
}
if(! httpRequest)
{
alert('\n\nGiving up :(\n\nCannot create an AJAX connection.');
return false;
}
httpRequest.onreadystatechange = function() { ContainerContents(httpRequest,id); };
httpRequest.open('GET',url,true);
httpRequest.send('');
} // function makeRequestGET()
content(s)
function ContainerContents(content,id)
{
try
{
if (content.readyState == 4)
{
if(content.status == 200) { document.getElementById(id).innerHTML=content.responseText; }
else { alert('\n\nThere was a problem with the request.\n\nStatus code: '+content.status+'\n'+content.statusText); }
}
}
catch(error) { alert('Error: '+error.name+' -- '+error.message); }
} // function ContainerContents()
</script>
</head>
body
<body>
see http://www.webreference.com/programming/javascript/w_b/index.html
>
<div id="AnIdentification">
<p>
Hi, I am text that will be replaced.
</p>
</div>
<a href="javascript:ReplaceElementID('lib-ajax-example-one.htm','AnIdentification')">
Click to see it in action.
</a>
Alternatively, click
<a href="javascript:ReplaceElementID('lib-ajax-example-two.htm','AnIdentification')">
two
</a>
<p>
relay(s)
<h4>external reference(s)</h4>
using php:
<a href="javascript:ReplaceElementID('lib-ajax-example-relay.php?http://www.cs.vu.nl/~eliens/media/ajax.txt','AnIdentification')">
Click to grab file.txt from another domain
</a>
or using
<a href="javascript:ReplaceElementID('lib-ajax-example-relay.cgi?http://www.cs.vu.nl/~eliens/media/ajax.txt','AnIdentification')">cgi</a>
<lp>
The <a href=lib-ajax-example-ajax.txt>ajax.txt</a> is also
available locally: lib-ajax-example-ajax.txt
</body>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.