2013-09-27 102 views
0

我需要一些幫助。 我已經使用下面的代碼編寫了我的投資組合, 我使用的是BBQ插件,有一個頁面調用portfolio.php,它導致頁面調用graphicdesign.php,它填充sql數據庫中的項目,點擊任何項目它會導致一個頁面調用graphicdesignpage.php與變量?p=page_id,點擊會從SQL數據庫中的數據加載到一個div調用#content後的結果,它加載罰款,它返回像這樣的URL-localhost/website/indexOfficial.php#graphicdesignpage.php?p=suiko_revival_runejQuery動態內容鏈接通過PHP從sql數據庫加載url,但刷新時不加載

但是當我刷新頁面,它不再加載任何特定頁面的數據編號

我該如何解決這個問題?

緊急

由於

問候

Kenwin

上的index.php

jQuery代碼

$(document).ready(function(){ 
var loadingImage = $('<img src="./preloader.gif"/>'); 
//initial 
$('body').fadeIn('slow'); 
if(document){ 
$('#content').append('<p id="loading"></p>'); 
    $('#loading').append(loadingImage); 
    $('#content-wrap').fadeOut('fast', function(){ 
    $('#loading').show(); 
    }); 
$('#content').load('home.php' + ' #content-wrap').fadeIn('slow'); 
    $('#loading').hide(); 
} 
//testcode 
//start of coding 
$('#nav ul li a, #pointnavwrapper a, .footleft a, #logo a').each(function(){ 
    $(this).attr('href', '#' + $(this).attr('href')); 
    }); 
    $(window).bind('hashchange', function(e){ 
    var url = e.fragment; 
    $('#content').load(url + '.php' + ' #content-wrap').hide().fadeIn('slow'); 

    //alert('loaded without fade out'); 
    //remove current state when another state active 
    $('#nav ul li.current, .webdesign a.current, .graphicdesign a.current, .printdesign a.current, .photography a.current, .personalprojects a.current, #webdesigntext.current, #graphicdesigntext.current, #printdesigntext.current, #photographytext.current, #personalprojectstext.current, .footleft a.current').removeClass('current'); 
    if(url){ 
    $('#content').append('<p id="loading"></p>'); 
    $('#loading').append(loadingImage); 
    //if hash 
    $('#nav ul li a[href="#' + url + '"]').parents('li').addClass('current'); 
    $('#content-wrap').fadeOut('fast', function(){ 
    $('#loading').show(); 
    }); 
    }else{ 
    //if no hash 
    $('#nav ul li:first-child').addClass('current'); 
    } 
    //dotnavs 
    if(url){ 
    $('#content').append('<p id="loading"></p>') 
    $('#loading').append(loadingImage); 
    //without list items parents 
    $('#webdesigntext a[href="#' + url + '"], #content a[href="#' + url + '"], .webdesign a[href="#' + url + '"], #graphicdesigntext a[href="#' + url + '"], .graphicdesign a[href="#' + url + '"], #printdesigntext a[href="#' + url + '"], .printdesign a[href="#' + url + '"], #photographytext a[href="#' + url + '"], .photography a[href="#' + url + '"], #personalprojectstext a[href="#' + url + '"], .personalprojects a[href="#' + url + '"], .footleft a[href="#' + url + '"]').addClass('current'); 
    $('#content-wrap').fadeOut('fast', function(){ 
    $('#loading').show(); 
    }); 
    }else{ 
    //if no hash 
    $('.footleft a:first-child').addClass('current'); 
    } 
    //CONTENT LINK FUNCTION HERE 

//end of content links clicks 
}); 
    //hide on exit 
// $("a").click(function(event){ 
//  event.preventDefault(); 
//  linkLocation = this.href; 
//  $('#content-wrap').fadeOut('fast',redirecturl(linkLocation)).hide();  
// }); 
// 
// function redirecturl(link) { 
//  document.location.href= link; 
// } 
//finish hide on exit 
    $(window).trigger('hashchange'); 
    //return false; 
}); 
//test content load links 
$('#portfoliowrapper a').live({ 
click:function(){ 
    $(this).attr('href', '#' + $(this).attr('href')); 
    $(window).bind('hashchange', function(e){ 
    var url = e.fragment; 
    $('#content').load(url + '.php' + ' #content-wrap').hide().fadeIn('slow'); 
    }); 
} 
}); 
//Dynamic Content load from php/sql 
$('#webdesignitem-wrapper a, #graphicdesignitem-wrapper a, #printdesignitem-wrapper a, #photographyitem-wrapper a, #personalprojectsitem-wrapper a').live({ 
click:function(e){ 
    $(this).attr('href', '#' + $(this).attr('href')); 
    $(window).bind('hashchange', function(e){ 
    var url=e.fragment; 
    $('#content').load(url).hide().fadeIn('slow'); 
    }); 
} 


}); 
// end of function 

上graphicdesign.php代碼

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> 
<script src="js/jquery.ba-bbq.min.js"></script> 
    <?php include ('inc/functions.php'); ?> 
    <?php require_once('Connections/connectdb.php'); ?> 
<?php 
mysql_select_db($database_connectdb, $connectdb); 
$query_rsGraphicDesign = "SELECT pg_id, pg_link, pg_identity, pg_client, pg_year_completed, pg_work_type, pg_keywords, pg_work_link, pg_roles, path,identity FROM tbl_pages,images WHERE pg_category = 2 AND images.identity=tbl_pages.pg_identity"; 
$rsGraphicDesign = mysql_query($query_rsGraphicDesign, $connectdb) or die(mysql_error()); 
$row_rsGraphicDesign = mysql_fetch_assoc($rsGraphicDesign); 
$totalRows_rsGraphicDesign = mysql_num_rows($rsGraphicDesign); 
?> 
<link href="style/style.css" rel="stylesheet" type="text/css" /> 
<div id="content-wrap"> 
<div id="graphicdesignitem-wrapper"> 
<h1>Graphic Design</h1> 
    <div id="graphic-tagline"><div class="statement">My Imaginations, Concepts and Ideas <br /> in digital art form......</div></div> 
     <?php if (($totalRows_rsGraphicDesign) > 0){ ?> 
    <?php do { ?> 
    <li class="graphicdesignitems"><a href="graphicdesignpage.php?p=<?php echo $row_rsGraphicDesign['pg_identity']; ?>"><div class="graphicdesignimages"><img src="<?php echo $row_rsGraphicDesign['path']; ?>"/></div><div class="graphicdesigntitles"><?php echo $row_rsGraphicDesign['pg_link']; ?></div></a> 
    </li> 
    <?php } while ($row_rsGraphicDesign = mysql_fetch_assoc($rsGraphicDesign)); ?> 
<?php } ?></div> 
</div> 
</div> 

上graphicdesignpage.php

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> 
<script src="js/jquery.ba-bbq.min.js"></script> 
<?php include ('admin/inc/fnc.php'); ?> 
<?php require_once('Connections/connectdb.php'); ?> 
<?php 
if (!function_exists("GetSQLValueString")) { 
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{ 
    if (PHP_VERSION < 6) { 
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; 
    } 
    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); 
    switch ($theType) { 
    case "text": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break;  
    case "long": 
    case "int": 
     $theValue = ($theValue != "") ? intval($theValue) : "NULL"; 
     break; 
    case "double": 
     $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; 
     break; 
    case "date": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break; 
    case "defined": 
     $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; 
     break; 
    } 
    return $theValue; 
} 
} 

mysql_select_db($database_connectdb, $connectdb); 
$query_rsContent = "SELECT pg_title,pg_cont,pg_description,identity,pg_client, pg_year_completed,pg_category, pg_work_type, pg_keywords, pg_work_link, pg_roles,nav_id,nav_name,path FROM tbl_pages,tbl_nav, images WHERE images.identity=tbl_pages.pg_identity AND tbl_nav.nav_id=tbl_pages.pg_category AND tbl_pages.pg_identity='$p'"; 
$rsContent = mysql_query($query_rsContent, $connectdb) or die(mysql_error()); 
$row_rsContent = mysql_fetch_assoc($rsContent); 
$totalRows_rsContent = mysql_num_rows($rsContent); 
?> 
<link href="style/style.css" rel="stylesheet" type="text/css" /> 
<div id="content-wrap"> 
<div id="pageheaderwrap"> 
<div id="pagethumbnail"><img src="<?php echo $row_rsContent['path']; ?>"/></div> 
<div id="metawrap"> 
<h1 class="graphicdesignheader"><?php echo $row_rsContent['pg_title']; ?></h1> 
<li>Category: <?php echo $row_rsContent['nav_name']; ?></li> 
<li>Year Completed: <?php echo $row_rsContent['pg_year_completed']; ?></li> 
<li>Client: <?php echo $row_rsContent['pg_client']; ?> 
<li>Type: <?php echo $row_rsContent['pg_work_type']; ?></li> 
<li>Roles: <?php echo $row_rsContent['pg_roles']; ?></li> 
<li>Link to work:<br/><a href="<?php echo $row_rsContent['pg_work_link']; ?>"><?php echo $row_rsContent['pg_work_link']; ?></a></li> 
</div> 
</div> 
<div id="pagecontentwrap"> 
<h2>About this workpiece:</h2> 
<?php echo $row_rsContent['pg_cont']; ?> 
</div> 
</div> 

回答

0

你正在一個AJAX調用PHP頁面將動態內容加載到DOM規範。在刷新頁面時,您將從Web服務器或緩存中檢索原始頁面。這個原始副本沒有動態內容,因此它對您檢索額外內容所做的ajax調用一無所知。去這樣做你想要的東西的一種方法是跟蹤的Ajax調用您已經使用cookie或localStorage,然後使Ajax調用,在你的cookies/localStorage由上$(document).ready()

+0

喜DGS感謝回答,我m仍然是jQuery的新手,你能告訴我如何去做你提到的東西嗎? 謝謝 – kenwin