0

I currently developing a site and have bumped into a problem.. (ajax loading stored urls) Thought someone could help..

First here is sample page layout:

<div id="main-container">
  <div id="top-menu">
    <a href="/link1" rel="ajax" />Link 1</a>
    <a href="/link2" rel="ajax" />Link 2</a>
  </div>
  <div id="content">
    <div id="results">
    <!-- category results go here -->
      <a href="/link1/category/cat-1/page/1" rel="ajax" />page 1</a>
      <a href="/link1/category/cat-2/page/2" rel="ajax" />page 2</a>         
    </div>
    <div id="categories">
      <a href="/link1/category/cat-1" rel="ajax" />cat 1</a>
      <a href="/link1/category/cat-2" rel="ajax" />cat 2</a>     
    </div>
  </div>
</div>

All is well if i want to load content by clicking links.. The hard part starts when I want to enable history support (create deep linkable urls)..

I cant figure out how to load necessary parts if full url is given e.g.

site.com/link1.html#/category/cat-1/page/

Some ideas I have:

  1. Each link has an attribute that tells where to load the content
  2. The url is sent to some controller that sends back data about where to load
  3. The hash has multiple parts and can be split into array and then each part is loaded

Well the result should be somewhat like facebooks navigation where you can navigate between home page, messages, friends list without a page refresh.. And then in each of the places you can navigate by sublinks..

4

2 回答 2

1

tnx :) 看看这个.. 它是一个非常好的插件,但是,经过一番思考,我发现了我缺少的部分..(可能应该包含 js 代码)

var hash = window.location.hash.substr(1);
var href = $('a[rel=ajax]').each(function(){
    var href = $(this).attr('href');
            var where = $(this).attr('test');
            //alert(where);
    if(hash==href.substr(0,href.length-5)){
        var toLoad = hash+'.html';
        $('#content_full').load(toLoad)
    }                                           
});

如果找到哈希(页面加载后),这些是调用的行..(我想让脚本有点太高级了..而不是使用加载数据的默认容器,我想从 url 获取位置..(不要问为什么..))

所以现在一切都应该正常工作了:)(我将为每个 ajax 链接添加一个关于它应该加载到哪个部分的变量,然后这些数据将被发送到 php 脚本,该脚本将输出必要的数据(只有想要的部分),如果不设置此 var,则脚本将输出完整内容)

于 2010-01-28T22:30:04.607 回答
0

查看Ben Alman 的烧烤:后退按钮和查询库插件

使添加后退按钮支持变得非常容易

于 2010-01-28T21:42:01.667 回答