рони,
Зацени
/* пишем аякс-функцию */
function ajax(obj){
try{var xhr = new XMLHttpRequest()
} catch(e1){try{
xhr = new ActiveXObject("Msxml2.XMLHTTP")
} catch(e2){try{
xhr = new ActiveXObject("Microsoft.XMLHTTP")
} catch(e3){ xhr = false
}
}
}
obj.type = obj.type || "GET" ;
if(obj.type === 'POST'){
var params = '';
for(i in obj.data){
params += i + '=' + obj.data[i] + '&';
}
params = params.slice(0, -1);
xhr.open("POST", obj.url, true);
xhr.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
//xhr.setRequestHeader("Content-length", params.length);
//xhr.setRequestHeader("Connection", "close");
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 = '?';
for(i in obj.data){
params += i + '=' + obj.data[i] + '&'
}
params = params.slice(0, -1);
params += "&nocache=" + Math.random() * 1000000
//console.log(params);
xhr.open("GET", obj.url + params, true);
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);
}
}
ajax({
url : './test_ajax.php',
type: 'POST',
dataType: 'Text',
data: {name: 'sash', _data_ : 'true'},
success: function(response){
document.getElementById('response').innerHTML =
response;
}
});