Полный вариант, не супер но сойдёт
function ajax(obj){
try{var xhr = new XMLHttpRequest()
} catch(e1){try{
var xhr = new ActiveXObject("Msxml2.XMLHTTP")
} catch(e2){try{
var xhr = new ActiveXObject("Microsoft.XMLHTTP")
} catch(e3){var xhr = false
}
}
}
obj.type = obj.type || "GET" ;
if(obj.type === 'POST'){
xhr.open("POST", obj.url, true);
var params = '';
if (typeof obj.data === 'string')
params = obj.data;
else if(typeof obj.data === 'object'){
if(obj.contentType === false){
params = obj.data;
console.log(params);
}
else{
for(var i in obj.data){
params += i + '=' + obj.data[i] + '&';
}
params = params.slice(0, -1);
console.log(params)
xhr.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
}
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); }
xhr.onreadystatechange = function() {
if(xhr.readyState == 4 && xhr.status == 200){
obj.success(this['response' + obj.dataType]);
}
else console.log( "Ajax error: " + this.statusText);
}
xhr.send(params);
}
else if(obj.type === "GET"){
var params = '?';
if (typeof obj.data === 'string')
params += obj.data;
else if(typeof obj.data === 'object'){
for(var i in obj.data){
params += i + '=' + encodeURIComponent(obj.data[i]) + '&'
}
params = params.slice(0, -1);
params += "&nocache=" + Math.random() * 1000000;
}
xhr.open("GET", obj.url + params, true);
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xhr.onreadystatechange = function() {
if(this.readyState == 4 && this.status == 200){
obj.success(this['response' + obj.dataType]);
}
else console.log( "Ajax error: " + this.statusText)
}
xhr.send(null);
}
}
document.forms.f1.onsubmit = function(e){
e.preventDefault();
var formObj = {};
var elem = document.forms.f1;
var inputs = elem.querySelectorAll('[name]');
for(var i = 0; i < inputs.length; i++){
formObj[inputs[i].name] = inputs[i].value;
if(window.FormData) {
var formData = new FormData(document.forms.f1);
}
}
// попытка отправки
ajax({
url : './test_ajax.php',
type: 'POST',
dataType: 'Text',
contentType : false,
data:formData,//{text: document.querySelector('[name=text]').value, _data_ : 'true'},
success: function(response){
document.getElementById('response').innerHTML =
response;
}
});
}