Source Code of: ajaxclient2.htm
Date Last Modified: May 02, 2009 - 01:59:18 AM
Size: 3 KB |
134 lines | 3,301 characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>AJAX Client</title>
<link rel="stylesheet" type="text/css" href="style/uname.css" />
<script type="text/javascript" src="winonload.js"></script> <script type="text/javascript">
function getXMLHTTP() { var req = false; // first, try to instantiate the native object if(window.XMLHttpRequest) { try { req = new XMLHttpRequest(); } catch(e) {} } // otherwise, try instantiating the ActiveX // object for IE. else if(window.ActiveXObject) { // just because creation of ActiveX objects // is supported, doesn't mean the XMLHTTP // object is available. So, let's try it. try { // try instantiating the newer version req = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { // otherwise, try the older version req = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} } } // req will either be the reference to the // interface or false on failure. return req; }
function handleReadyStateChange() { // ignore unless complete readyState if (request.readyState == 4) { // Ignore unless successful. // You might choose to handle errors // rather than ignore them. if (request.status == 200) { // act on the response var xmlbody = request.responseXML; request = null; processResponse(xmlbody); } } }
function processResponse(oXML) { if (!oXML) return; if (!oXML.documentElement) return; var doc = oXML.documentElement; var unames = doc.getElementsByTagName('username'); var msgs = new Array(); for (var i=0; i<unames.length; i++) { var u = unames.item(i); var username = u.getAttribute('value'); var availability = u.getAttribute('available'); if (availability == 'true') { availability = 'available'; } else { availability = 'not available'; } msgs[msgs.length] = 'Username '+ username +' is '+ availability; } ul = document.createElement('ul'); ul.id = 'msg'; for (var k=0; k<msgs.length; k++) { var li = document.createElement('li'); var txt = document.createTextNode(msgs[k]); li.appendChild(txt); ul.appendChild(li); } var maindiv = document.getElementById('maindiv'); maindiv.parentNode.insertBefore(ul,maindiv); addedul = ul; }
function fireRequest() { request = getXMLHTTP(); request.onreadystatechange = handleReadyStateChange; request.open('get', 'ajaxresponder2.php'); request.send(null); }
function initAJAX() { // make DOM modifications if (document.getElementById) { if (document.getElementById('main')) { document.getElementById('main').onclick = fireRequest; } } // end if }
addBodyOnload(initAJAX);
var request = null;
</script>
</head> <body>
<h1>AJAX Test</h1> <form action="" method="post" id="signupform"> <ul> <li>Simulate Username Request: <input type="button" name="main" id="main" value="Go" /></li> </ul> </form>
<div> <div id="maindiv"> <p>main main main</p> </div> </div>
</body> </html>
|
A Derivative Work of: PHP Source Code Utility - Version 1.0.0 Copyright ©
0php.com 2002.