【问题标题】:url change without anchor tag and refresh using ajax没有锚标记的 url 更改并使用 ajax 刷新
【发布时间】:2013-06-21 22:09:33
【问题描述】:

根据我的客户需要,重定向没有锚标记的页面并刷新页面, 并根据页面外观更改 URL。我对此一无所知。 我可以将 ajax 用于页面内容。但我不知道没有 URL 更改选项 页面刷新或重定向。我怎么能用ajax j-query做到这一点。任何人都可以指导我解决这个问题。谢谢提前

示例网址

www.samplesite.com/contact.php -> 没有锚标签。和页面刷新这个 url 需要在 php 上工作。

【问题讨论】:

    标签: php jquery ajax url


    【解决方案1】:

    我认为您正在寻找有关新的 HTML5 History API (pushstate) 的信息,此链接有详细教程。

    http://diveintohtml5.info/history.html

    【讨论】:

      【解决方案2】:

      你可以使用下面的函数来做到这一点。

      if(pageurl!=window.location){
        window.history.pushState({path:pageurl},'',pageurl);
      } 
      

      【讨论】:

        【解决方案3】:

        您可以使用以下 javascript 函数

        window.location.assign('http://www.samplesite.com/contact.php'); // keeps the current page in browser history
        
        window.location.replace('http://www.samplesite.com/contact.php'); // replaces the current page in browser history
        
        window.location = 'http://www.samplesite.com/contact.php'; // the same as assign() and is backward compatible even with the oldest browsers
        

        jsfiddle

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-05-16
          • 2011-04-29
          • 1970-01-01
          • 2013-09-07
          • 2011-07-19
          • 2013-12-20
          相关资源
          最近更新 更多