Using a variable name in XMLHttpRequest

Posted by Paul on Stack Overflow See other posts from Stack Overflow or by Paul
Published on 2010-05-17T18:56:02Z Indexed on 2010/05/17 19:00 UTC
Read the original article Hit count: 271

Filed under:
|
|
|
|

Hi All, I am using jQuery and trying to load a variable in place of a named xml file. My Code:

$(document).ready(function() { 
        // bind 'myForm' and provide a simple callback function 
        $('#theForm').ajaxForm(function(responseXML2) { 

            var myxml = responseXML2;
            alert(responseXML2);
            displayResult();


           }); 
}); 
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
  {
  alert("loading xmlhttprequest");
  xhttp=new XMLHttpRequest();
  }
else
  {
  alert("loading activeX");
  xhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
alert("bottom load");
xhttp.open("GET",dname,false);
xhttp.send();
return xhttp.responseXML;
}

function displayResult()
{
alert("setting vars");

alert("displayResult called");

//xml=loadXMLDoc(responseXML2);  //tried this and the line below, among others
xml=responseXML2;
alert("xmlDocLoaded");
xsl=loadXMLDoc("xslt-test.xsl");
alert("XSLloaded");
// code for IE
if (window.ActiveXObject)
  {
  alert("IE");
  ex=xml.transformNode(xsl);
  document.getElementById("ieiresponse").innerHTML=ex;
  }
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
  {
  alert("notIE");
  xsltProcessor=new XSLTProcessor();
  xsltProcessor.importStylesheet(xsl);
  resultDocument = xsltProcessor.transformToFragment(xml,document);
  document.getElementById("ieiresponse").appendChild(resultDocument);
  }
}

In the code above I want to have:

//xml=loadXMLDoc(responseXML2);  //tried this and the line below, among others
xml=responseXML2;

instead of a named file:

xsl=loadXMLDoc("example.xml");

When I run through the code, it works if I name the file, but when I use the variable, (which does show up in alerts, so is being pulled), it stops the code at the above line (placing the variable as the xml file)

Any help would be much appreciated! Thank you in advance.

© Stack Overflow or respective owner

Related posts about Xml

Related posts about xmlhttprequest