This is my code.
function ajax() {
var ajaxRequest;
try {
ajaxRequest = new XMLHttpRequest();
}
catch (e) {
try {
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
alert("Your browser broke!");
return false;
}
}
}
return ajaxRequest;
}
var ajax = ajax();
ajax.Message = function (method, l) {
ajax.open(method, url, false);
ajax.send();
ajax.onreadystatechange = function () {
if (ajax.readyState == 4 && ajax.status == 200) {}
}
}
Every time I want to send a request, I need to use this function, but when I look the code in Youtube, or Twitter, I see that they don’t work like this.
Is there a short way to send AJAX? I mean only using JavaScript, without using jQuery.
Other sites use more or less what you posted or jQuery which is more or less what you posted under the covers.
You want the above shorter?
http://anthologyoi.com/dev/short-ajax-script.html