我想通過jQuery將ID傳遞給urlstring而無需刷新jQuery和#
標籤,以便我可以通過php $_get['ID']
函數獲取ID。通過jquery傳遞ID到url字符串,然後通過PHP選擇它沒有頁面刷新?
但問題是,
- 如果我使用
#
,頁面沒有得到刷新,但是PHP也從URL挑ID。 - 如果我不使用#,那麼php會選擇該ID,但Page會刷新。
我想傳遞一個id到php而不刷新頁面。
//javascript
function com(id) {
location.href = '#?ID=id'; //by this way way,page doesn't refresh, ID appears in the url string but ID is not picked by PHP as # is there
// location.href = '?ID=id'; this way way, ID appears in the url string , ID is also picked by PHP as # is there.But page get refreshed.
$.ajax({
type: "Post",
url: "getdata.php",
async: true,
cache: false,
success: function(data) {},
});
}
//php for getdata.php
<?php echo $_GET['ID']; ?>
你必須有一個頁面刷新因爲PHP是服務器端。它在重新加載之前無法獲取url中的更改。但阿賈克斯可能是一個更好的辦法 – 2012-12-01 06:43:20