【问题标题】:How to implement history plugin for prototypejs?如何为prototypejs实现历史插件?
【发布时间】:2011-10-20 06:45:40
【问题描述】:

我将 AJAX 与 prototypejs 一起使用。现在我想使用浏览器的后退/前进按钮重定向到已经访问过的 AJAX 链接。我找到了this plugin,但我不知道我的项目中必须包含哪个文件以及从哪里开始。我正在使用以下prototypejs 代码来处理带有JSON 响应的AJAX 请求。

function ajaxRequest(url) {

parent.location.hash = url;

new Ajax.Request( url, {

      method: 'get',
      onSuccess: function( transport ) {

        // get json response
        var json = transport.responseText.evalJSON( true );

        for(var id in json) {
            $(id).innerHTML = json[id];
        }
    },     
    onFailure: function() {         
        alert('Error with AJAX request.'); 
    }  
});

return false;
}

有什么想法吗?

谢谢

【问题讨论】:

    标签: javascript ajax prototypejs hashcode history.js


    【解决方案1】:

    您可以使用Really Simple History。您通过一个隐藏的 iframe 路由您的 ajax 调用,该 iframe 又从父页面调用它们。当用户按下 BACK 时,它会使 iframe 返回,因此执行之前的 ajax 调用。

    【讨论】:

    • 是的,Prototype 比这还要老。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-12
    • 1970-01-01
    • 2010-11-27
    • 1970-01-01
    • 1970-01-01
    • 2017-08-11
    相关资源
    最近更新 更多