Please follow this link to see Truly Cross Browser XMLHTTPR
AJAX Demo : Simple , Cross Browser & Beginner Level
- Simple hello world code ( Tested on Firefox and IE ).
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />
<script type=”text/javascript” language=”javascript”>
var http_request = false;
function makeRequest(url) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,… code
// checks Universal Browser Read for Netscape family browser
// furthur info
//http://www.captain.at/howto-ajax-permission-denied-xmlhttprequest.php
try {
netscape.security.PrivilegeManager.enablePrivilege(“UniversalBrowserRead”);
} catch (e) {
alert(“Permission UniversalBrowserRead denied.”);
}
// creates XMLHttpRequest for Netscape family browser
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType(‘text/xml’);
}
// creates XMLHttpRequest for IE
} else if (window.ActiveXObject) {
try {
http_request = new ActiveXObject(“Msxml2.XMLHTTP”);
} catch (e) {
try {
http_request = new ActiveXObject(“Microsoft.XMLHTTP”);
} catch (e) {}
}
}
if (!http_request) {
alert(‘Giving up
Cannot create an XMLHTTP instance’);
return false;
}
else{
window.alert(“welcome http_request object created”)
}
http_request.onreadystatechange = alertContents;
http_request.open(‘GET’, url, true);
http_request.send(null);
}
//———— if there’s is a problem
function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
alert(http_request.responseText);
} else {
alert(‘There was a problem with the request.’);
}
}
}
//————————-
</script>
</head>
<body>
<input type=”button” name=”button” value=”create XMLHttpRequest Object”
onclick=”makeRequest()”>
</body>
</html>