Hello everyone, I am doing a simple chat on pure Javascript and I ran into one problem:
Namely, with cross-browser compatibility ... When creating an xmlHttpRequest object, problems begin in the new Google Chrome and Mozilla Firefox browsers (not tested in others). Now I looked at how it works in IE8 - everything is OK with the xmlHttpRequest object, but there are many other problems ...
Here is the code:
function createXmlHttpRequestObject() { var xmlHttp; try{ xmlHttp = new xmlHttpRequest(); } catch(e){ var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"); for (var i = 0; i < XmlHttpVersions.length && !xmlHttp; i++) { try{ xmlHttp = new ActiveXObject(XmlHttpVersions[i]); } catch (e){} } } if (!xmlHttp) { alert("Ошибка создания объекта xmlHttpRequest."); }else{ return xmlHttp; } }
In the Google Chrome and Mozilla browsers, Firefox constantly pops up an alert ("Error creating xmlHttpRequest object.");
How do I need to change this code to make it cross-browser and make it work in modern browsers?