AJAX In Action [38]
Define callback handler
var ready=req.readyState;
var data=null;
if (ready==READY_STATE_COMPLETE){
Check readyState
data=req.responseText;
Read response data
}else{
data="loading...["+ready+"]";
}
toConsole(data);
}
function toConsole(data){
if (console!=null){
var newline=document.createElement("div");
console.appendChild(newline);
var txt=document.createTextNode(data);
newline.appendChild(txt);
}
}
window.onload=function(){
console=document.getElementById('console');
sendRequest("data.txt");
}
Licensed to jonathan zheng 64 CHAPTER 2 First steps with Ajax