2011-12-19 69 views
1

我需要幫助,這正是我正在嘗試做的。我有兩個文件。 「index.php」和「realtime.php」index.php基於URL參數「country_code」顯示來自特定國家的新聞,realtime.php每2秒更新一次新聞列表。我想要的是realtime.php獲取index.php的當前url參數,以便它只能通過url參數更新來自特定國家/地區的新聞。我真的需要這個幫助。再次感謝你。將URL參數傳遞給javascript和php中的頁面

腳本的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); 
} 
}); 

而對於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 } ?> 
+3

我真的不明白這個問題,你不告訴我們你已經嘗試過。 *緊急編輯將不勝感激*。 – 2011-12-19 08:55:24

+0

請描述你需要更多...我無法理解你的意思。 – 2011-12-19 09:11:55

回答

0

至於我能理解這個問題的腳本,你需要兩樣東西:

  1. mod重寫來傳遞URL vari能夠腳本
  2. 一個片段獲得可變

所以,那很容易。首先,你寫的東西是這樣的:

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

而在你realtime.php可以使用$_GET['country_code']使用你的參數。

+0

謝謝你的回答,這是我真正想要做的。我有兩個文件。 「index.php」和「realtime.php」index.php基於URL參數「country_code」顯示來自特定國家的新聞,realtime.php每2秒更新一次新聞列表。我想要的是爲realtime.php獲取index.php的當前URL參數,以便它只能通過URL參數更新來自特定國家/地區的新聞。我真的需要這個幫助。再次感謝你。 – 2011-12-20 06:44:32

+0

因此,你有兩個框架,並與realtime.php一個必須知道另一個的URL參數?對於Javascript,您可以使用jQuery,如下所示:http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html因此,您可以獲取值,併爲例如,在後臺通過AJAX調用realtime.php。 – 2011-12-20 14:20:03