Page 1 of 1

passing xml string to javascript function. Not successful.

Posted: Mon Sep 13, 2010 2:47 am
by jdoe
Hi.

I am trying to pass xml data string from a clicked link to a javascript function.
Eventually, I wish to have a javascript function to pass this info back to php. (For AJAX purpose)

//this is my xml data string, which DIDN'T WORK.
$myXMLdata = "<?xml version="1.0"?> <archive><articleid>6</articleid></archive>";

//this modified xml data string, which WORKED.
$myXMLdata = " <archive><articleid>6</articleid></archive>";

$option_link = "<a href=\"javascript:;\" onclick=\"return showAlert('$myXMLdata ');\">";

When I click on the link, the javascript function below will be called, and the text will be displayed in a pop up window.

function showAlert(myText) {
alert('The text is ' + myText + '.');
}

Could you please help to explain why the $myXMLdata with "...<?xml version="1.0"?>..." will not fire up the showAlert function, but the $myXMLdata without "...<?xml version="1.0"?>..." will call the showAlert Function.

Thanks.

Re: passing xml string to javascript function. Not successfu

Posted: Mon Sep 13, 2010 4:33 am
by cpetercarter
You have placed double quotation marks inside a double-quoted string.

Code: Select all

$myXMLdata = "<?xml version="1.0"?> <archive><articleid>6</articleid></archive>"; 
Try:

Code: Select all

$myXMLdata = '<?xml version="1.0"?> <archive><articleid>6</articleid></archive>'; 

Re: passing xml string to javascript function. Not successfu

Posted: Mon Sep 13, 2010 4:52 am
by jdoe
hi cpetercarter,

thanks for your reply. however, it didn't work.
$myXMLdata = '<?xml version="1.0"?> <archive><articleid>6</articleid></archive>';

these works: (removing the double-quotes around the 1.0)
$myXMLdata = '<?xml version=1.0?> <archive><articleid>6</articleid></archive>';
$myXMLdata = "<?xml version=1.0?> <archive><articleid>6</articleid></archive>";

Anyway, i have found a workaround solution.

Instead of using the new DOMDocument('1.0') to create my XML data string, I am just using simple text $myXMLData = "<archive><articleid>6</articleid></archive>". This will not have the <?xml version="1.0"?>

Tqvm.