简体   繁体   English

要求Ajax请求的结果

[英]Urls for results of Ajax requests

Hi guys I've developed a google maps application witha neat search feature - however I've noticed that I would like to have something like what the facebook guys have done as in having a hardlink to a page that is generated by an ajax query. 嗨,大家好,我开发了一个具有整洁的搜索功能的google maps应用程序-但是,我注意到我想要做一个像Facebook的家伙那样做的事情,就像硬链接到ajax查询生成的页面一样。 Example you click on a link in facebook and it appends to the current url and you can copy paste the new url to get the requested page ... how do I implement something like that... 例如,您单击facebook中的链接,并将其附加到当前URL,然后可以复制粘贴新的URL以获取所请求的页面...我该如何实现类似的功能...

sounds like you want to update the browser's url with a link that can be used to re-visit the page in its current state. 听起来好像您想使用链接来更新浏览器的url,该链接可用于以当前状态重新访问该页面。 that can be done by manipulating the browser history. 可以通过操纵浏览器历史记录来完成。

a good solution for this is: 一个好的解决方案是:

Really Simple History 真正简单的历史

http://code.google.com/p/reallysimplehistory/ http://code.google.com/p/reallysimplehistory/

Really Simple History is a lightweight JavaScript library for the management of bookmarking and browser history in Ajax/DHTML applications. Really Simple History是一个轻量级的JavaScript库,用于管理Ajax / DHTML应用程序中的书签和浏览器历史记录。 RSH serializes application data in an internal JavaScript cache so that bookmarks and the back button can be used to return your application to an earlier state. RSH在内部JavaScript缓存中序列化应用程序数据,以便可以使用书签和后退按钮使您的应用程序返回到较早的状态。

check out this excellent example: 看看这个出色的例子:

http://www.justise.com/2009/01/26/enabling-the-back-button-in-ajax-applications/ http://www.justise.com/2009/01/26/enabling-the-back-button-in-ajax-applications/

You can use the location.hash (the part of the URL after the #) to set "hard links" from withing JavaScript. 您可以使用location.hash (#后面的URL部分)来设置JavaScript的“硬链接”。 This does not cause the page to reload, like changing the location.href does, but you can fetch the value and use it in JavaScript. 这不会像更改location.href那样导致重新加载页面,但是您可以获取值并在JavaScript中使用它。

Consider this example: 考虑以下示例:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<head>
    <title>Hash test</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script type="text/javascript">
    window.onload = function() {
        // The substring(1) removes the # from the hash.
        var hash = window.location.hash.substring(1);

        // Use a default value if no has was passed.
        if(hash == '') {
            hash = 'Nothing';
        }

        // Use the value.
        document.getElementById('selection').innerHTML = hash;
    }

    /** Sets the hash and updates the page value */
    function setHash(newHash) {
        window.location.hash = newHash;
        document.getElementById('selection').innerHTML = newHash;
    }
    </script>
</head>
<body>
    <div>
        <div>
            <a href="javascript: void();" onclick="setHash('page1');">Page 1</a> | 
            <a href="javascript: void();" onclick="setHash('page2');">Page 2</a> |
            <a href="javascript: void();" onclick="setHash('page3');">Page 3</a>
        </div>
        <div>
            You have selected: <span id="selection">...</span>
        </div>
    </div>
</body>
</html>

When you click on one of the page links, the location.hash is changed, the URL of the browser is updated and the value used in the page is changed. 当您单击页面链接之一时, location.hash会更改,浏览器的URL将更新,并且页面中使用的值也会更改。 If the user then copies the URL directly from the address bar, or bookmarks it, the selected page will be reloaded when the URL is requested again. 如果用户然后直接从地址栏中复制URL或将其添加为书签,则再次请求URL时将重新加载所选页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM