在javascript和php中传递URL参数到页面
Passing URL parameter to a page in javascript and php
我需要帮助,这就是我实际上想做的。我有两个文件。"index.php"answers"realtime.php" index.php根据url参数"country_code"显示来自特定国家的新闻,realtime.php每2秒更新一次新闻列表。我想要的是real - time.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);
}
});
和real - time.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 } ?>
在我看来,你需要两件事:
- 一个mod重写来传递URL变量到你的脚本获取变量的代码片段
这很简单。首先像这样写:
RewriteEngine on
RewriteRule ^index'.php?country_code=(.*)$ realtime.php?country_code=$1
在你的real - time.php中你可以使用$_GET['country_code']
来使用你的参数
相关文章:
- JS:检查URL中的参数,然后迭代一个参数为var的函数
- 传递包含'%的参数'在URL中
- 如何在router.get()方法中传递url作为参数
- javascript中url中的Regex参数
- 如何在reactrouterv2.+中从URL获取参数
- 使用express.具有多个url和可选参数的Router()
- 如何在所有ajax调用中向URL添加参数
- 通过Javascript将HTML中的电话号码与URL参数进行交换
- 如何使用Javascript从URL参数中自动填充文本字段
- XMLHttpRequest.open()AJAX中的参数url
- 如何将Google Analytics配置为将URL参数作为单个页面进行跟踪
- 使用应用程序状态js和视图在angular js url上传递两个参数
- 在url参数javascript中存储键值对列表
- backbone.js-映射标准url参数-使用多个参数
- 模版启动错误-类型错误(“参数”url'必须是字符串,而不是“+类型的url”)
- UI 路由器参数 URL 不起作用,只是重定向到 /
- 在Select2中传递参数url
- 使用jQuery/Javascript(querystring)获取查询字符串参数url值
- Javascript -重定向参数URL只有一次
- 替换url参数-url被破坏