I'm currently diving into the world of AJAX and looking into different methods of creating HttpRequests. So far, I've brainstormed a few approaches:
function one() {
if(window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
alert('Other');
} else if (window.ActiveXObject) {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
alert('windows');
}
return xhr;
}
function two() {
if(window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
alert('Other');
} else if (!window.XMLHttpRequest) {
xhr = new ActiveXObject('Microsoft.XMLHTTP');
alert('windows');
}
return xhr;
}
function three() {
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
alert('Other');
} else {
xhr = new ActiveXObject();
alert('windows');
}
return xhr;
}
function four() {
try {
xhr = new XMLHttpRequest();
alert('Other');
} catch (e) {
xhr = new ActiveXObject();
alert('windows');
}
return xhr;
}
If there are any alternative ways to create this request that anyone would like to share, I would greatly appreciate it! One thing I love about JavaScript is its versatility in achieving tasks, so exploring all options is something I enjoy.