AJAX & Prototype Page 3 - The Ajax Approach to ACP: A Simple Example |
In this section, I talk about the script at the bottom of the first page. This script is in the BODY element. Remember that JavaScript in the HEAD element is executed when it is called, while JavaScript in the BODY element is executed when the page is loaded. This is the script: <script type="text/javascript">
var xmlHttp;
try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Your browser does not support AJAX!"); } } } xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { theArray[2] = xmlHttp.responseText; } }
xmlHttp.open("GET","sendText.pl",true); xmlHttp.send(null); </script> The features here are the same as in the previous part of the series. The only difference is that, in the previous part of the series, all of these statements are in a function. Here they are not in a function, so they are executed as the page is loaded. I will not repeat the explanation of the code. The complete code can be downloaded at:
blog comments powered by Disqus |
|
|
|
|
|
|
|