Skip to content

Instantly share code, notes, and snippets.

@viveksinghggits
Created August 13, 2016 06:41
Show Gist options
  • Save viveksinghggits/aedac838bbf66ca5e05ace190ddd04c5 to your computer and use it in GitHub Desktop.
Save viveksinghggits/aedac838bbf66ca5e05ace190ddd04c5 to your computer and use it in GitHub Desktop.
making a cross platform XMLHttpRequest
function createXMLHttpRequestObject(){
if(window.XMLHttpRequest){
xmlHTTPRequest = new XMLHttpRequest();
}
else{
xmlHTTPRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlHTTPRequest;
}
@viveksinghggits
Copy link
Author

A cross platform XMLHttpRequestObject can be created using this code snippet.

@ch3ll0v3k
Copy link

`function( ) {

var xhttp;
try{ 
    xhttp = new ActiveXObject("MSXML2.XMLHTTP");
}catch (e){
    try { 
        xhttp = new ActiveXObject("Microsoft.XMLHTTP"); } 
    catch (e){ xhttp = new XMLHttpRequest(); } 
}

return xhttp;

}
`

@viveksinghggits
Copy link
Author

yes is is beter option I think

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment