Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 7th, 2010, 02:42 PM
Registered User
 
Join Date: Jul 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Passing xml from php to javascript?

Hey guys, I'm new to php. Right now I'm trying to pass a xml string from php to javascript. I've tried with simple strings, and it works. Code like this:

<?php
$color = "green";
?>

<script language="JavaScript">
document.write("<?php echo($color);?>");
</script>

would output:

green.

But when I have something like this:

<?php
include 'xml.php';
?>

<script language="JavaScript">
document.write("<?php echo($xml);?>");
</script>

with 'xml.php' defining a variable $xml that includes an xml string, it no longer works, it gives some thing like:

- <script language="JavaScript">
document.write("
- <markers>
...
xml info
...
</markers>
");
</script>

Can someone please let me know how to get xml string from php to javascript? Thanks a lot!

Jim

Last edited by csxcsx; July 7th, 2010 at 02:44 PM..
 
Old July 12th, 2010, 03:53 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 479
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via MSN to surendran Send a message via Yahoo to surendran
Default

hi,
the problem here is the $xml variable having multi line text, rather calling the xml inside javascript, directly you can call the xml page into javascript, see the sample site below
http://www.levmuchnik.net/Content/Pr...avascript.html
__________________
surendran
(Anything is Possible)
http://www.suren.info
http://ssuren.spaces.msn.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing data from PHP to Javascript oldBroh Javascript How-To 12 June 12th, 2008 11:12 PM
Passing javascript variable to html or php ashraf_gawdat Javascript How-To 3 July 12th, 2006 02:48 PM
Passing data from PHP to Javascript youngj PHP How-To 4 February 22nd, 2006 11:55 PM
Passing PHP variables to javascript wfrisch Pro PHP 10 April 5th, 2005 05:13 AM
passing javascript to php by Snib ismnanie Pro PHP 5 February 4th, 2005 07:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.