I am a beginner in AJAX. I had a question I couldn’t find on the internet so I came here :). My first question is has to do with the block of code below.
function createXHR() {
var iexhr...;
iexhr = ["MSXML2.XMLHttp.7.0", "MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp", "MSXML3.XMLHttp", "Microsoft.XMLHttp"];
}
My question to the code above is: Throughout my googling and research I collect code samples that use different versions xmlhttprequest. I wanted to create a cross browser xhr, and was wondering if all of these versions were important to keep, or should I only be using one?
I don’t think you want any of those.
There’s really two versions of XHRs that you need to worry about:
window.ActiveXObject( "Microsoft.XMLHTTP")for oldIE andwindow.XMLHttpRequest()for everybody else.The usual pattern you’ll see is something like:
Or something like that, depending on what you’re trying to do.
However, there’s a lot more to XHR than returning Objects, such as monitoring state and errors, so this is precisely why folks use libraries for this sort of thing. Don’t reinvent the wheel.