Jump to content

pass xml data from php to javascript


rvdokkum

Recommended Posts

i read xml data from the tumblr api using curl and put it in an textarea on an html page.

<?phpfunction curl_get_contents ($url) {	$curl = curl_init();	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);	curl_setopt($curl, CURLOPT_URL, $url);	$html = curl_exec($curl);	curl_close($curl);		return $html;}$aap = curl_get_contents("http://myblog.tumblr.com/api/read" );echo $aap;?>

i try to adjust the following script to read the xml from the textarea and use it.http://www.w3schools.com/xsl/xsl_client.asponly the xml data is in the wrong format.how do i decode / encode it so it will work?

Link to comment
Share on other sites

i try to adjust the following script to read the xml from the textarea and use it.
which textarea are you refering to? are you trying to get the data from the page in textarea node?
Link to comment
Share on other sites

PHP can only generate content at the start of the page. Once you've gotten the information from that page you can then decode it in PHP (preferred) and print it somewhere to be used by the Javascript or you can print the entire contents to a hidden page element and decode it with Javascript. So if the XML is in the wrong format then it's an issue with the page you are calling and you should refer to that page. The contents of a textarea exists only in Javascript which is client-side. Meaning the server doesn't know what you've inputed into it until you submit it to the server. So you would have to submit the contents first or use Ajax to submit the content a file that records the information to a file or database. Then on the page you are requesting the information you could have another Ajax request a file that reads and prints this information. Pages cannot directly communicate with one another so you will need to use some sort of medium to give the illusion that they are.If I'm not mistaken by what you are asking.

Link to comment
Share on other sites

PHP can only generate content at the start of the page. Once you've gotten the information from that page you can then decode it in PHP (preferred) and print it somewhere to be used by the Javascript or you can print the entire contents to a hidden page element and decode it with Javascript. So if the XML is in the wrong format then it's an issue with the page you are calling and you should refer to that page. The contents of a textarea exists only in Javascript which is client-side. Meaning the server doesn't know what you've inputed into it until you submit it to the server. So you would have to submit the contents first or use Ajax to submit the content a file that records the information to a file or database. Then on the page you are requesting the information you could have another Ajax request a file that reads and prints this information. Pages cannot directly communicate with one another so you will need to use some sort of medium to give the illusion that they are.If I'm not mistaken by what you are asking.
i have a page that is generated by the cms Modx.using php i fill a textarea on the page with xml datathen using<body onload="displayResult()">i call a function to read the textarea and make it into an xml object so it can be used in this function:http://www.w3schools.com/xsl/xsl_client.aspbut i don't know how to get it in the right encoding to work.when i read the same data from an xml file it works.but i try to make it dynamicaly so it can read the data directly from the tumblr api call.i try to use this function to make the string data into an xml objecthttp://www.hardcode.nl/subcategory_1/artic...l-in-javascriptbut it seems i get html and body tags with it where i only need xml data
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...