When I click the test button I get no result, no errors whatsoever. As you can probably see I'm extremely beginner when it comes to javascript. What solutions will you recommend so I can write this "class" in order to work? I want it to work more like jQuery ajax call $.ajax({}); ...
var Ajax = function(){
this.method = null;
this.url = null;
this.headerType = null;
this.data = null;
function request (callback) {
var xml = new XMLHttpRequest();
xml.open(this.method, this.url, true);
xml.setRequestHeader(this.headerType || "Content-type", "application/x-www-form-urlencoded");
xml.onreadystatechange = function() {
if(xml.readyState == 4) {
if(xml.status == 200) {
callback(xml.responseText);
}
}
}
xml.send(this.data || null);
}
}
document.getElementById('test').addEventListener('click', function() {
Ajax({
method : 'GET',
url : 'test.php',
request : function(response) {
document.getElementById('testResult').innerHTML = response;
}
});
});
thank you
EDIT: here is the html code
<button id="test">Get data</button>
<div id="testResult"></div>