Link to home
Create AccountLog in
Avatar of Keith McElroy
Keith McElroy

asked on

JQuery equivalent to Active X - XML DOM Document

Replace ActiveXObject with browser-agnostic JQuery 

What is the Jquery code to replace the following so it works in Edge, Chrome, etc....


var xDoc = new ActiveXObject("MSXML.DOMDocument");
  xDoc.async = false;
  xDoc.loadXML( sRequestXML )


I'm trying this without success

var xDoc = $.parseXML(sRequestXML)




Avatar of Keith McElroy
Keith McElroy

ASKER

Additional information

Looks like the above code is working.  It's this next section that is failing...

   if (typeof(Request) == 'object')
      this.m_oServerHTTP = new ActiveXObject("MSXML2.SERVERXMLHTTP");
   else
      this.m_oServerHTTP = new ActiveXObject("Microsoft.XMLHTTP");
   
   try
   {
      this.m_oServerHTTP.open( "POST", "api.dll", false );
   }
   catch(e)
   {
      this.m_oServerHTTP.open( "POST", "api.dll", false );
   }

   if (typeof(Request) == 'object')
      this.m_oServerHTTP.setOption(2) = 4096;
   
   this.m_oServerHTTP.send( oRequestXML );
   
 
So real question is how to I adapt the following to handle an xml object
 $.ajax({data:{},url: "api.dll",cache:false}).done(function(returnxml)
   {
                 
   })
This is what I have so far.  The xml document seems to be a valid object but the POST fails.
I need to return the reponse to the GetResponseXML() function per below.

function _GetRecords()
{

   var oRequestXML = this.GetRequestXMLDocument();
   var runner = ""
   alert("Line 556")
   $.ajax({type:"POST", data:oRequestXML,url: "api.dll",cache:false;async:false}).done(function(returnXML)
   {
      alert("Line 558")            
   })  
   alert("Line 560 " )
   return returnXML.GetResponseXML();
}


Latest try, still no work:
I feel like it would work if I could make the oRequestXML back to a string or
improve the code so the api received it properly.  The API works fine from server side vb code in asp and in c#

function _GetRecords()
{

   var oRequestXML = this.GetRequestXMLDocument();
   var returnXML= ""
   alert("OK up to here")
   $.ajax({type:"POST", data: oRequestXML, dataType: "xml",  contentType: "application/xml", url: "api.dll", cache:false, async:false}).done(function(returnXML)
   {
      alert("Line 558")            
   })  
   alert("Line 560 " )
   return returnXML.GetResponseXML();
}
Avatar of ste5an
Please do yourself and us a a favour and embed your code using the code tags (the </> button in the toolbar). Your posts are hard to read and copying code is also not easy.
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Bitte, ich verwende das Code-Snippet Tool.

Graicas, excelente progreso.  Un problema meno...

Code Sample 1 - Works -  fantastico!
$.ajax({type:"POST", data:sRequestXML, dataType: "text",  contentType: "text/xml", url: "api.dll", cache:false, async:false}).done(function(returnXML)
   {
      alert("Line 548 g " + returnXML)            
   })

Open in new window

Code Sample 2 - Fails but would work if oRequestXML.text() was changed so that it returned the text version of the oRequestXML object.  I thought oRequestXML.xml would work, but it does not.  If I can getoRequestXML.text() to represent the text string of the xml object, this baby is going to work!  Any ideas what I am missing with $(oRequestXML).text().  I've tried it with and without the jquery $ and not hitting it.

     $.ajax({type:"POST", data: $(oRequestXML).text(), dataType: "text",  contentType: "text/xml", url: "api.dll", cache:false, async:false}).done(function(returnXML)
   {
      alert("Line 566 f")            
   })   

Open in new window

leakim971m,  merci, magnifique!
se qui suit a fonctionne along with your suggestion of using .text
function xmlToString(xmlData) { 

    var xmlString;
    //IE
    if (window.ActiveXObject){
        xmlString = xmlData.xml;
    }
    // code for Mozilla, Firefox, Opera, etc.
    else{
        xmlString = (new XMLSerializer()).serializeToString(xmlData);
    }
    return xmlString;
}   

Open in new window


votre français est magnifique
enchante, j'apprends  le francais.  il aide a l'apprentissage de la technologie!