Use XMLHttpRequest to send and read data : XMLHttpRequest « Ajax Layer « JavaScript DHTML






Use XMLHttpRequest to send and read data

 
<html>
<head>
<title>ISBN</title>
</head>
<body>
<div id="data"></div>
<script type="text/javascript">
function readyAJAX() {
    try {
        return new XMLHttpRequest();
    } catch(e) {
        try {
            return new ActiveXObject('Msxml2.XMLHTTP');
        } catch(e) {
            try {
                return new ActiveXObject('Microsoft.XMLHTTP');
            } catch(e) {
                return "A newer browser is needed.";
            }
        }
    }
}
var requestObj = readyAJAX();
var url = "http://www.yourserver.org/isbn.php?isbn=11234567890";
requestObj.open("GET",url,true);
requestObj.send();
requestObj.onreadystatechange = function() {
    if (requestObj.readyState == 4) {
        if (requestObj.status == 200) {
            document.write(requestObj.responseText);
        } else {
            document.write(requestObj.statusText);
        }
    }
}
</script>
</body>
</html>

   
  








Related examples in the same category

1.Is your Browser Ajax ready
2.Ajax and php