Reputation: 2201
I'm trying to create a demo bar just like wordpress theme companies do .So far, i was able to achieve a bit of it with
$('#window').load('index.php?action=theme&themeID=5');
Now i want to be able to create specific URLs which trigger specific code. For example, the above mentioned code runs if i go to
http://mysite.com/theme.php?id=5
How do i do that? is there any way to do the same with php?
Upvotes: 1
Views: 764
Reputation: 70169
Easily done with PHP, you just have to echo the $_GET['id']
value inside your script:
echo "<script type='text/javascript'>$('#window').load('index.php?action=theme&themeID=".$_GET['id']."');</script>";
or
<script type='text/javascript'>
$('#window').load('index.php?action=theme&themeID=<?php echo $_GET['id'] ?>');
</script>
And yes, GET
parameters are unsafe, just as POST
parameters may also be manipulated. You should valid to check if the parameter being passed is valid in your PHP
page beforing echoing it directly to your script.
Upvotes: 2
Reputation: 1748
From what I gather you are trying to dynamically change javascript based on the url of the page?
<script type='text/javascript'>
$('#window').load('index.php?action=theme&themeID=<?php echo $_GET['id']; ?>');
</script>
You might want to cast the value to an int or something though in order to secure things a bit.
Upvotes: 2