1

我正在尝试像 wordpress 主题公司一样创建一个演示栏。到目前为止,我能够通过

$('#window').load('index.php?action=theme&themeID=5');

现在我希望能够创建触发特定代码的特定 URL。例如,如果我去上面提到的代码运行

http://mysite.com/theme.php?id=5

我怎么做?有没有办法用php做同样的事情?

4

2 回答 2

2

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>

Reference

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.

于 2012-06-05T06:03:10.447 回答
2

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.

于 2012-06-05T06:03:30.693 回答