【问题标题】:Getting History.js to work with Ajax-Solr让 History.js 与 Ajax-Solr 一起工作
【发布时间】:2013-05-24 22:06:07
【问题描述】:

我正在使用 Solr 4.3.0 并为接口实现 Ajax-Solr。但是,Ajax-Solr 不会自动保存状态。有一个 ParameterStore 和 ParameterHashStore 方法,但它们不适用于旧版浏览器。我使用了我的 google-fu 并发现以下内容,但它没有按预期工作:

https://github.com/evolvingweb/ajax-solr/pull/23

...我想出了更多资源:

<script>
var Manager;
(function ($) { 
Manager.setStore(new AjaxSolr.ParameterHashStore()); 
Manager.store.exposed = [ 'fq', 'q', 'start' ]; 
Manager.init(); 

// Establish Variables
var History = window.History; // Note: We are using a capital H instead of a lower h
    if ( !History.enabled ) {
         // History.js is disabled for this browser.
         // This is because we can optionally choose to support HTML4 browsers or not.
         return false;
     }
     State = History.getState(),

    // Bind to State Change
    History.Adapter.bind(window,'statechange',function(){ // Note: We are using   
statechange instead of popstate
        // Log the State
       var State = History.getState(); // Note: We are using History.getState() instead 
of event.state
        History.log('statechange:', State.data, State.title, State.url);
    });

    // Log Initial State
    History.log('initial:', State.data, State.title, State.url);

})(jQuery);
</script>

但它不起作用。所有浏览器中的前进和后退按钮都已损坏,并且没有任何内容记录到控制台。

我缺少什么或者 v4.3.0 现在本身就很无聊并且需要补丁?

非常感谢任何帮助。谢谢!

【问题讨论】:

  • 另外,我忘了提到即使我添加了 Manager.store.exposed 代码,Ajax-Solr 也不会公开 URL 参数

标签: javascript ajax apache solr history.js


【解决方案1】:

我对 AJAX-Solr 一无所知。但我认为与您讨论一些事情可能会有所帮助。

如果 AJAX-Solr 的工作方式与普通 AJAX 相同,那么 AJAX-Solr 将执行一些服务器端功能并将其输出到客户端(当然不会刷新实际页面)。因此,您应该将触发 ajax 调用的函数放在您的 History.Adapter.bind(window,'statechange',function() 中。

关于State = History.getState();,它负责返回历史栈中推送状态的状态数据(url、title、ajax参数)。请阅读 github 上有关 hisrory.js 的文档。另请注意,您在代码中使用逗号而不是分号。此外,您将调用此函数两次。在 Bind 函数中只调用一次以获取状态参数并在 ajax 调用中使用它们(以便在浏览浏览器后退按钮时刷新页面部分)。

我建议你也阅读Back-Forward buttons of browser are showing weird behaviour. History.js,也许它会帮助你了解ajax关于Bind的定位。

祝你好运。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-11
    • 1970-01-01
    相关资源
    最近更新 更多