passing xml string to javascript function. Not successful.
Posted: Mon Sep 13, 2010 2:47 am
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.
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.