Echoed, embedded php within javascript -
summary
currently have webpage in running javascript allow user create ul list. want process list, saving file on server need done php of course.
goal
the overall goal hoping solve how embed php within javascript. keep in mind javascript being echoed html page surrounded single quotes of course.
what have tried
function test(){ var ul = document.getelementbyid("playlist"); var playlist = ""; (i = 1; < ul.children.length; i++){ var item = ul.childnodes[i]; playlist += item.innerhtml + string.fromcharcode(13); } playlist = playlist.slice(0, -1); jsvar = \'<?php echo $playlist;?>\'; alert(jsvar); }
the variable playlist generated fine. @ end trying simple playlist variable. simply, now, trying pass playlist variable int php script echo variable me display alert.
the above code result in popup box has literal displayed. reason isn't recognizing php script rather treating string.. missing simple or totally obvious?
i have looked @ many posts on seem work using similar idea above don't..
thanks in advance.
more things have tried
i found online verify php5 installed:
sudo apt-get update sudo apt-get install libapache2-mod-php5 sudo a2enmod php5 sudo service apache2 restart
apache restarted still see literal string...
trial ajax
i tried method of passing variable through ajax , loading outside php file. used following loaded php file but..
$.ajax( { url: "save_playlist.php", type: "post", data: { id1: playlist}, success: function (result) { alert(id); var url = "save_playlist.php"; window.location.href = url; }})
when having on save_playlist.php:
session_start(); $a =isset($_post['id1'])?$_post['id1']:'not yet'; echo $a ;
nothing passed.. , way use:
<script type="text/javascript" src="jquery.js"></script>
for ajax work.
Comments
Post a Comment