topical media & game development
professional-ria-03-ajax.js / js
// Ajax functions
// (c) joe marini 2005
var xmlhttp = null; // the XMLHttpRequest object
function createRequest()
{
var reqObj = null;
try {
reqObj = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (err) {
try {
reqObj = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (err2) {
try {
reqObj = new XMLHttpRequest();
}
catch (err3) {
reqObj = null;
}
}
}
return reqObj;
}
function getURL(url, callback, isAsync)
{
// if the request is already executing then stop it (executing means in a state
// other than 0 (uninitialized) or 4 (completed).
if (xmlhttp != null) {
if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0)
xmlhttp.abort();
}
xmlhttp = createRequest();
if (xmlhttp != null) {
alert("ajax.js :getURL:"+url+"\n\ncallback:"+callback+"\n\nxmlxmlhttp);
xmlhttp.open('GET', url, isAsync);
xmlhttp.onreadystatechange=callback;
xmlhttp.send(null);
}
}
function postURL(url, callback, isAsync, data)
{
// if the request is already executing then stop it (executing means in a state
// other than 0 (uninitialized) or 4 (completed).
if (xmlhttp != null) {
if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0)
xmlhttp.abort();
}
xmlhttp = createRequest();
if (xmlhttp != null) {
xmlhttp.open("POST", url, isAsync);
xmlhttp.onreadystatechange=callback;
xmlhttp.send(data);
}
}
(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.