Jump to content

Set parameter in XSL using AJAX


john6384

Recommended Posts

I am trying to set a parameter in my XSL to be a PHP variable that I know is working as it can be seen using an alert in the AJAX.

 

Element keeps coming through as empty - javascript error.

 

Any more code, explanation needed then please say.

 

Cheers

 

var username = '<?php echo $username;?>';	
var myXMLHTTPRequest = new XMLHttpRequest();
var myXSLTProcessor = new XSLTProcessor();

alert(username);

//load the XSL file
myXMLHTTPRequest.open("GET", "mnu.xsl", false);
myXMLHTTPRequest.send(null);

//get the XML document	
xslStylesheet = myXMLHTTPRequest.responseXML;
myXSLTProcessor.importStylesheet(xslStylesheet);

//load the xml file
myXMLHTTPRequest.open("GET", "mnu.xml", false);
myXMLHTTPRequest.send(null);

var xmlSource = myXMLHTTPRequest.responseXML;

alert(myXMLHTTPRequest.responseText);

myXSLTProcessor.setParameter(null, "username", username);
fragment = myXSLTProcessor.transformToFragment(xmlSource, document);

var element = document.getElementById("menuTarget");

while(element.firstChild) 
{
	element.removeChild(element.firstChild);
}

element.appendChild(fragment);

Link to comment
Share on other sites

I think that it is to do with the order that my code executes i.e. element has not been populated or assigned anything before it is used - this gives an empty.

 

To solve this I tried to make the whole of the code shown a function that is called after another function is used to setup the page - point of this was to make element not empty.

 

This did not work - please suggest how I can debug this or any other ideas.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.