It's really easy to write Object Oriented Javascript
javascript Code:
function DoSomethingWithResult(result) { // result = responseText } function Ajax { this.GetXmlHttpRequest = function() { // no browser compatibility return new XMLHttpRequest(); } this.Request = function(url, callback) { var xmlHttp = this.GetXmlHttpRequest(); xmlHttp.onreadystatechange = function() { if(xmlHttp.readyState == 4) { if(xmlHttp.status == 200) { // call your function! callback(xmlHttp.responseText); } } } xmlHttp.open("GET", url, true); xmlHttp.send(null); } }
Then the call is simple:
javascript Code:
var ajax = new Ajax(); ajax.Request("page.php?param1=this¶m2=that", DoSomethingWithResult);




Reply With Quote