Alternative to XRM Javascript calling webservice using ActiveX

眉间皱痕 提交于 2019-12-24 12:39:57

问题


I have a problem on CRM javascript when calling a webservice from browsers other than IE. See my code below for the web service call implementation.

function RetrieveMultipleEntity(targetEntity, conditionAttributeName, conditionAttributeValue, targetId, targetAttribute)
{
// Prepare variables to retrieve the contacts.
var authenticationHeader = GenerateAuthenticationHeader();

// Prepare the SOAP message.
// var xml = (the SOAP message)

var xHReq = new ActiveXObject("Msxml2.XMLHTTP");

xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// Capture the result.
var resultXml = xHReq.responseXML;

return resultXml;
}

There's a problem on this line:

var xHReq = new ActiveXObject("Msxml2.XMLHTTP");

It runs correctly on IE because it can use ActiveXObject but unfortunately it fails on Firefox/Chrome. I'm looking for suggestions on an alternative of calling the web service. Can anyone help me? Thanks!


回答1:


try with

var xHReq = new XMLHttpRequest();

it works also for IE7+



来源:https://stackoverflow.com/questions/15632821/alternative-to-xrm-javascript-calling-webservice-using-activex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!