我有在IE中工作的功能,但在其他浏览器中不起作用 请帮助重写它以实现跨浏览器兼容性
function Fetch(xml) {
var Xml = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">";
Xml += GenerateAuthenticationHeader();
Xml += "<soap:Body>";
Xml += "<Fetch xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">";
Xml += "<fetchXml>";
Xml += CrmEncodeDecode.CrmXmlEncode(xml); // Microsoft _HtmlEncode function
Xml += "</fetchXml>";
Xml += "</Fetch>";
Xml += "</soap:Body>";
Xml += "</soap:Envelope>";
// Microsot CreateXmlHttp function
if ( XMLHttpRequest != null){
var XmlHttp = new XMLHttpRequest();
}
else{
var XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
XmlHttp.open("POST", "/mscrmservices/2007/crmservice.asmx", false); //Sync Request
XmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
XmlHttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Fetch");
XmlHttp.send(Xml);
var ie = (window.ActiveXObject) ? true : false;
var XmlDoc = (ie) ? new ActiveXObject("MSXML2.DOMDocument") : new window.XMLHttpRequest();
XmlDoc.async = false;
XmlDoc.resolveExternals = false;
XmlDoc.loadXML(XmlHttp.responseXML.text);
return XmlDoc;
}
如何更改代码,使其在Google Chrome中运行
答案 0 :(得分:0)
Try this code。我不确定它是否可以在Chrome中运行,并确保查看有关responseXML与ResponseText可能存在问题的评论,但它应该使响应更容易处理。
如果你是在2011年,为什么2007年的终点?它已被弃用,甚至不适用于某些CRM在线实例,并且不适用于任何CRM 2013实例。
答案 1 :(得分:0)
我建议将XrmServicesToolkit合并到您的跨浏览器解决方案中,这将极大地简化SOAP请求的执行:
var request = "<request i:type='b:WhoAmIRequest' xmlns:a='http://schemas.microsoft.com/xrm/2011/Contracts' xmlns:b='http://schemas.microsoft.com/crm/2011/Contracts'><a:Parameters xmlns:c='http://schemas.datacontract.org/2004/07/System.Collections.Generic' /><a:RequestId i:nil='true' /><a:RequestName>WhoAmI</a:RequestName></request>";
var whoAmI = XrmServiceToolkit.Soap.Execute(request);