What Rasmus Lerdorf is talking about AJAX
Are you blindly following any ajax library to work your way.
Take a look what Rasmus is talking about AJAX
He follows the rule of simplicity as he described in his framework approach.
The very basic of ajax structure -
Javascript
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == “Microsoft Internet Explorer”){
ro = new ActiveXObject(“Microsoft.XMLHTTP”);
}else{
ro = new XMLHttpRequest();
}
return ro;
}
var http = createRequestObject();
function sndReq(action) {
http.open(‘get’, ‘rpc.php?action=’+action);
http.onreadystatechange = handleResponse;
http.send(null);
}
function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
var update = new Array();
if(response.indexOf(‘|’ != -1)) {
update = response.split(‘|’);
document.getElementById(update[0]).innerHTML = update[1];
}
}
}
HTML
<a href=”javascript:sndReq(‘foo’)”>[foo]</a>
<div id=”foo” />
server side script(rpc.php) -
switch($_REQUEST['action']) {
case ‘foo’:
/* do something */
echo “foo|foo done”;
break;
…
}
Thats all. Everything else is just building on top of this.
Source : http://news.php.net/php.general/219164
Tags: AJAX
No Comments
Comments RSS
TrackBack Identifier URI
No comments. Be the first.
Leave a comment