0
通過AJAX方法加載的頁面。 index.php文件的基本頁面,profile.php是裝
jQuery的頁面:( 「後」 無關,與HTML請求)
$('<a/>', {href: '?userID='+post['userID']+'#profile'}).text(post['firstName']+' '+post['lastName'])
HTML:
<a href="?userID=1#profile">Firstname Lastname</a>
原始網址(點擊後)
http://########/#####/index.php?userID=1#home
$ _GET的print_r上profile.php:
Array()
根據要求;阿賈克斯負載的JavaScript(的index.php):
//AJAX page loading
$(document).ready(function(){
//Default page
if(!window.location.hash)
window.location.hash = '#home';
//Check page reference
checkURL();
//Update nav
$('#main-nav li').on("click", function(){
$('#main-nav li').removeClass('active');
$(this).addClass('active');
//Assign each link a new onclick event, using their own hash as a parameter
checkURL(this.hash);
});
//check for a change in the URL every 250 ms to detect if the history buttons have been used
setInterval("checkURL()",250);
});
//Store the current URL hash
var lasturl="";
function checkURL(hash){
if(!hash)
//if no parameter is provided, use the hash value from the current address
hash=window.location.hash;
if(hash != lasturl) {
//If hash changed, update current hash and load new one
lasturl=hash;
loadPage(hash);
}
}
function loadPage(url) {
//Adjust page name
url=url.replace('#','');
url=url+'.php';
//AJAX load page contents in to main content div
$('#content').load(url);
}
凡在你的代碼,你加載'profile.php '? – Tchoupi 2013-03-11 13:52:50
它在index.php document.ready函數中。這是相當長的,但頁面加載工作正常(除了上述問題)。 – 2013-03-11 13:55:35
我們需要看到發送ajax請求的部分。 – bfavaretto 2013-03-11 13:58:47