ballhogjoni Posted November 10, 2008 Share Posted November 10, 2008 I want to alert the object in javascript, but I can't find a function that will do this. I want to do something like print_r() but for javascript. Quote Link to comment Share on other sites More sharing options...
flyhoney Posted November 10, 2008 Share Posted November 10, 2008 I don't know of any way to do that. But if you are having trouble debugging javascript, use the firebug plugin for firefox, it can help lotz. Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted November 10, 2008 Share Posted November 10, 2008 As in <?php $var = array('first','second'); ?> <script> alert( <?php print_r($var); ?> ); Something similar maybe, as it is untested. Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted November 10, 2008 Share Posted November 10, 2008 It won't work like that because PHP is executed on the server before sending any response back to the browser. What you might do is set a javascript timer that uses an Ajax call query a PHP script at intervals Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted November 11, 2008 Share Posted November 11, 2008 Exactly that's why it will work, try it, i admit that one might not work. But this one will <?php $var = "test, proving you wrong"; echo "<script>alert('".$var."');</script>"; ?> Unless he is trying to do something to make php interact with the JS after the page has loaded, but he didn't say he did. If you do then look at ajax. Quote Link to comment Share on other sites More sharing options...
premiso Posted November 11, 2008 Share Posted November 11, 2008 Not sure why this is in the PHP section, but I am pretty sure you can do the toString in javascript. <Script type="text/javascript"> var myfriends=new Array("John", "Bob", "Sue") alert(myfriends.toString()); </script> from http://www.javascriptkit.com/jsref/arrays.shtml Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.