Discussion about Ajax programming and the Sajax Toolkit by ModernMethod
|
chinwei Guest |
this html file is called ajax.html:, anyone can help make it work in IE? <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en" dir="ltr"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Developing Web Applications with Ajax - Example</title> <script type="text/javascript"><!-- function ajaxRead(file) { var xmlObj = null; if(window.XMLHttpRequest) { xmlObj = new XMLHttpRequest(); } else if(window.ActiveXObject) { xmlObj = new ActiveXObject("Microsoft.XMLHTTP"); } else { return; } xmlObj.onreadystatechange = function() { if(xmlObj.readyState == 4) { var myVar1 = xmlObj.responseXML; //alert(xmlObj.responseText); var myVar2 = myVar1.getElementsByTagName('data')[0]; var myVar3 = myVar2.firstChild; updateObj('xmlObj', myVar3.data); } } xmlObj.open ('GET', file, true); xmlObj.send (''); } function updateObj(obj, data) { document.getElementById(obj).innerHTML = data; } //--></script> </head> <body> <h1>Hi this is the First Ajax</h1> <p id="xmlObj"> data in the xml file: <a href="data.xml" onclick="ajaxRead('data.xml'); this.style.display='none'; return false">View XML.</a> </p> </body> </html> here is the XML file to be used, it is saved at the same foplder as the above file, called data.xml: <?xml version="1.0" encoding="UTF-8"?> <root> <data> 888888888888888888 </data> </root> |
|
Rem Guest |
Code: function ajaxRead(url) { // code for Mozilla Firefox if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); xmlhttp.open("GET",url,true); xmlhttp.onreadystatechange=state_Change; xmlhttp.send(null); } // code for IE else if (window.ActiveXObject) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); if (xmlhttp) { xmlhttp.open("GET",url,true); xmlhttp.onreadystatechange=state_Change; xmlhttp.send(); } } } you should check the status of the object before trying to use it. This way you can be sure that the object is ready to handle your requests. this can be done like this: i Code: f(xmlhttp.readyState == 4)
{ if (xmlhttp.status==200) { //do your stuff } else { alert("Could not handle the request. Status text : " + xmlhttp.statusText) } } |
|
Guest |
Poker Gambling room online poker highest |
|
Guest |
online casinos blackjack |
|
Guest |
|
|
Rem Guest |
I posted something above but it had nothing to do with the framework. In fact, why go through all the trouble of doing it all yourself when Sajax can relieve you of that burden? Cheers to all |
|
Guest |
|