jQuery动态内容链接通过php从SQL数据库加载URL,但在刷新时不会加载


jQuery dynamic content links load url from sql database via php but when refresh it doesn't load

我需要一些帮助。我使用以下代码对我的投资组合进行了编码,我正在使用BBQ插件,有一个页面调用组合.php它会导致一个页面调用图形设计.php它填充sql数据库中的项目,当单击任何项目时,它会导致带有变量?p=page_id的页面调用graphicdesignpage.php,单击后的结果会将sql数据库中的数据加载到div调用#content中, 它加载正常,它在 url 中返回类似这样的内容localhost/website/indexOfficial.php#graphicdesignpage.php?p=suiko_revival_rune

但是当我刷新页面时,它不再加载特定页面ID的任何数据

我该如何解决这个问题?

紧急

谢谢

问候

肯温

索引上的j查询代码.php

 $(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 

图形设计上的代码.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>

图形设计页面上的代码.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>

您正在对 php 页面进行 ajax 调用,该调用会将动态内容加载到 DOM 中。刷新页面时,您是从 Web 服务器或缓存中检索原始页面。此原始副本中没有任何动态内容,因此它对您为检索额外内容而进行的 ajax 调用一无所知。执行所需操作的一种方法是跟踪您使用 cookie 或 localStorage 进行的 ajax 调用,然后在 cookie/localStorage 中进行 ajax 调用$(document).ready()