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.
passing xml string to javascript function. Not successful.
Moderator: General Moderators
-
cpetercarter
- Forum Contributor
- Posts: 474
- Joined: Sat Jul 25, 2009 2:00 am
Re: passing xml string to javascript function. Not successfu
You have placed double quotation marks inside a double-quoted string.
Try:
Code: Select all
$myXMLdata = "<?xml version="1.0"?> <archive><articleid>6</articleid></archive>"; Code: Select all
$myXMLdata = '<?xml version="1.0"?> <archive><articleid>6</articleid></archive>'; Re: passing xml string to javascript function. Not successfu
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.
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.