js/j06ajax.php
<html>
<head>
<title> <?php echo basename(__file__, '.php'); ?> </title>
<script type="text/javascript">
ajaxReq = null;
function clean(obj) {
if (obj == null)
return 'null';
var sr1 = obj.toString();
var sr2 = (sr1.length < 1700 ? sr1 : sr1.substr(0, 1700) + '...');
var sr3 = sr2.replace('>', '> ', 'g');
sr3 = sr3.replace('<', '<', 'g');
sr3 = sr3.replace('\n', '\\n', 'g');
return 'typeof=' + typeof obj + ' constructor=' + obj.constructor.name + ' toString.length=' +sr1.length + ': ' + sr3 ;
}
function showEv(t, ev) {
var ul = document.getElementById('evRes');
var t = new Date().toISOString() + ' ' + t; // + ', event=' + String(ev);
var n = document.createElement('li');
n.innerHTML = t;
ul.insertBefore(n, ul.firstChild);
}
function doAjax(url) {
showEv('creating AJAX request for ' + url + 'doc.url=' + document.URL);
ajaxReq = new XMLHttpRequest()
ajaxReq.onreadystatechange = ajaxListener;
ajaxReq.open('GET', url);
ajaxReq.send(null);
}
function ajaxListener() {
showEv('ajaxListener readyState=' + ajaxReq.readyState + ', status=' + ajaxReq.status + ', statusText=' + ajaxReq.statusText + ', responseText=' + clean(ajaxReq.responseText));
}
</script>
</head>
<body>
<h1>produce AJAX requests</h1>
AJAX = asynchronous JavaScript and XML <br>
<input type="button" value="AJAX 'ajaxResponse1.txt'" onclick="doAjax('ajaxResponse1.txt');" />
<input type="button" value="AJAX 'gibtEsGarNicht'" onclick="doAjax('gibtEsGarNicht');" />
<input type="button" value="AJAX 'j01write.php'" onclick="doAjax('j01write.php');" />
<input type="button" value="AJAX '.'" onclick="doAjax('.');" />
<h1>ajax events</h1>
<ul id="evRes">
<li>pseudo event in html</li>
</ul>
<h1>Source <?php echo __file__; ?> </h1>
<?php highlight_file(__file__) ?>
</body>
</html>