实现Web 2.0导航系统的最佳方式 [英] Best way to implement a Web 2.0 navigation system

查看:188
本文介绍了实现Web 2.0导航系统的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在这里是我的情况:我做一个CMS。当链接被点击,我想使用Ajax动态加载页面。链接中的问题!

Now here is my situation: I'm making a CMS. When links are clicked, i would like the pages to load dynamically using Ajax. The problem in the links!

在地址栏中实时更改地址的唯一方法是使用定位标记。但是PHP没有获取锚点标签,因此我无法使用PHP在网站加载页面内容。
如果我使用查询字符串加载页面,查询字符串不能在链接的点击地址栏中更新,因为这将重新加载页面。

The only way to change the address in the address bar real-time is to use anchor tags. But PHP doesn't get the anchor tags, thus I can't load page content on site load using PHP. And if i were to load the pages using a query string, the query string couldn't be updated in the address bar at the click of a link, since that would reload the page.

我假设Javascript可以检查地址,将锚标签保存在cookie中并重新加载页面,但我不想去这样的长度。

I suppose Javascript could check the address, save the anchor tag in a cookie and reload the page, but I'd rather not have to go to such lengths.

有人知道这个问题的解决方案吗?

Does anyone know a solution to this problem?

推荐答案

我想出了以下解决方案。

There was a similar question not so long ago, and I came up with the following solution.

您的网址应该指向真实的网页,以使其工作的js禁用用户。点击处理程序应该处理ajax请求。哈希应该包含url,并且包含& ajax 以指示请求的类型。

Your urls should point to real pages in order to get it work in for js disabled users. The click handlers should handle ajax requests. Hash should contain the url, and a part like &ajax to indicate the type of the request.

该请求是从ajax只是发送内容。

If the request is from ajax simply send the content. If it is not, wrap the content into header and footer to respond with a full site.

网址应该与链接到ajax生成的哈希并使用它们作为链接一起工作。如果没有,请将内容包含到页眉和页脚中以响应完整的网站。

Urls should work with linking to ajax generated hashes and using them as links. The whole idea is basically mimics the kind of behavior you can see on facebook.

Javascript

// click handler for ajax links
function goToWithAjax(hash) {
  hash = hash.href ? hash.getAttribute("href", 2) : hash;
  ajax( hash, function( response ) {
    document.getElementById("content").innerHTML = response;
  });
  hash = ("#!/" + hash).replace("//","/");
  window.location.hash = hash;
  return false;
}

.htaccess

auto_prepend_file = "prepend.php"  
auto_append_file  = "append.php"  

前缀

$url   = $_SERVER['REQUEST_URI'];
$parts = explode('#!', $url);
$hash  = isset($parts[1]) ? $parts[1] : false;

// redirect if there is a hash part
if ($hash) {
  header("Location: $hash");
}

// find out if it's an ajax request
$ajax = strstr($url, "&ajax");

// we need header if it's not ajax
if (!$ajax) {
  get_header();
}

追加

// we need footer if it's not ajax
if (!$ajax) {
  get_footer();
}

get_header()
$ b

get_header()

function get_header() {

echo <<< END
<html>
<head></head>
<body>
<div id="page">
  <div id="header">
    <div id="logo"></div>
    <ul id="nav">menu...</ul>
  </div>
  <div id="content">
END;

}

get_footer() p>

get_footer()

function get_footer() {

echo <<< END
  </div> <!-- end of #content --->
  <div id="footer">(c) me</footer>
</div> <!-- end of #page --->
</body>
</html>
END;

}

这篇关于实现Web 2.0导航系统的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆