Depending on the browser, I would like to determine which object should be used. For IE <10, this should be XDomainRequestfor the rest XMLHttpRequest.
XDomainRequest
XMLHttpRequest
if(window.XDomainRequest) //basically 'if IE' //XDomainRequest else //XMLHttpRequest
Since IE10 supports Cross-Origin Resource Sharing, it is best to use an object with it XMLHttpRequest. This code will not work anymore (I suppose IE10 still supports XDomainRequest, correct me, if I am wrong, I cannot verify it). Checking the browser directly is not the safest way to detect things. So my question is, what is the best way to determine which object should be used? I am looking for a clean JS solution (non-jQuery).
, .
var useXDR = window.XDomainRequest && (window.XMLHttpRequest && new XMLHttpRequest().responseType === undefined);
, IE10 responseType XHR, IE, XHR2, undefined.
, , XDR , XHR - , - , , XmlHttpRequest, XDR.
XHR2 XDR, XHR, URL- /, .