3 Tips – Upgrade Your CRM 2011 AJAX Calls to Support Chrome, Firefox & Safari

Gayan Perera, 05 March 2013

Rollup 12/Polaris added support for Chrome, Firefox & Safari, therefore we need to ensure custom javascript works across all of the above browsers. One of the things we’ve seen with xRM implementations are AJAX calls using ActiveXObjects. ActiveXObject works fine in IE but fails with other browsers.

Here are 3 tips on how you can quickly make your AJAX calls compatible with IE, Chrome, Firefox & Safari.

1. The request – use XMLHttpRequest instead. Please note that you will not be able to make cross domain calls using XMLHttpRequest.

    var request = new ActiveXObject("Microsoft.XMLHTTP");
    var request = new XMLHttpRequest();

2. Parsing the response – Avoid using the XMLDOM and XPath, use a combination of firstChild and childNodes.


   
var response = new ActiveXObject("Microsoft.XMLDOM");
    response.loadXML(request.responseXML.selectSingleNode("..."));

    var nodes = request.responseXML.childNodes; OR responseXML.firstChild;

3. Parsing the xml

a. Use .nodeName instead of .baseName – when you do this ensure that you use the full namespace. Eg: “a:EntityReference” instead of just “EntityReference”

b. Use a conditional select on node text, eg: node.text will work in IE but in Chrome you’ll need to use node.textContent

c. Avoid using XPath