在javascript和php中向页面传递URL参数

在javascript和php中向页面传递URL参数,php,javascript,url,Php,Javascript,Url,我需要帮助,这才是我真正想做的。我有两个文件。“index.php”和“realtime.php”index.php根据url参数“country_code”显示特定国家/地区的新闻,realtime.php每2秒更新一次新闻列表。我想要的是realtime.php获取index.php的当前url参数,以便它只能根据url参数更新来自特定国家/地区的新闻。我真的需要这个帮助。再次感谢你 index.php的脚本 <script type="text/javascript"> $(d

我需要帮助,这才是我真正想做的。我有两个文件。“index.php”和“realtime.php”index.php根据url参数“country_code”显示特定国家/地区的新闻,realtime.php每2秒更新一次新闻列表。我想要的是realtime.php获取index.php的当前url参数,以便它只能根据url参数更新来自特定国家/地区的新闻。我真的需要这个帮助。再次感谢你

index.php的脚本

<script type="text/javascript">
$(document).ready(function () {
$.arte({'ajax_url': '../realtime.php?lastid='+$('.postitem:first').attr('id'), 'on_success': update_field, 'time': 1000}).start();
function update_field(data)
{
    $("#realtimeupdate").html(data);
}
});

$(文档).ready(函数(){
$.arte({'ajax_url':'../realtime.php?lastid='+$('.positem:first').attr('id'),'on_success':update_字段,'time':1000}).start();
函数更新_字段(数据)
{
$(“#实时更新”).html(数据);
}
});

以及realtime.php的脚本

<?php

include"customDB.php";
$lastid = $_REQUEST['lastid'];
$query = 'SELECT count(*) as newpost FROM wp_posts WHERE country_code = "XXXXX" AND    post_id > "'.$lastid.'"';
$result = mysql_query($query);
$rec = mysql_fetch_object($result);
if($rec->newpost){ ?>
<a href="" id="newpostlink">(<?php echo $rec->newpost; ?>) new posts</a>
<script type="text/javascript">document.title = '(<?php echo $rec->newpost; ?>) new  posts'</script>
<?php } ?>

document.title=“()新帖子”

就我理解这个问题而言,您需要两件事:

  • 将URL变量传递给脚本的mod rewrite
  • 获取变量的代码段
  • 所以,这很容易。首先,你可以这样写:

    RewriteEngine on
    RewriteRule ^index\.php?country_code=(.*)$ realtime.php?country_code=$1
    

    在你的realtime.php中,你可以使用
    $\u GET['country\u code']
    来使用你的参数。

    我不太理解这个问题,你也没有告诉我们你已经尝试过了。紧急编辑将不胜感激。请描述您需要更多。。。我不明白你的意思。谢谢你的回答,这就是我真正想做的。我有两个文件。“index.php”和“realtime.php”index.php根据url参数“country_code”显示特定国家/地区的新闻,realtime.php每2秒更新一次新闻列表。我想要的是realtime.php获取index.php的当前URL参数,以便它只能根据URL参数更新来自特定国家/地区的新闻。我真的需要这个帮助。再次感谢您。您有两个框架,一个是realtime.php,您必须知道另一个的URL参数吗?对于Javascript,您可以使用jQuery,如下所述:因此您可以获取值,例如,在后台通过AJAX调用realtime.php。