dtxooq1020 2012-08-25 01:28
浏览 71

使用Ajax / Javascript更改PHP URL变量

I have made up a webpage on a private server as part of a full website redesign. The page calls up files such as contact.php with AJAX code to show the contents within a DIV layer, so that the actual page is still index.php but looks like a contact page.

What I would like to do is have a function that, when such links to make the AJAX call are clicked, will dynamically change the URL so that if somebody clicks the Contact link the page URL looks like index.php?page=contact (as an example).

Facebook has the sort of system I am looking to usewhen you click on a photo from the news feed and then change to another photo from the same user/gallery. I don't want something that just changes the URL from a hash tag (#), as that just adds complication to the design, whereas one that puts a PHP variable into the URL simply means I can write a PHP code to include the file directly if the variable is set.

Thanks.

  • 写回答

1条回答 默认 最新

  • dtq26360 2012-08-25 01:51
    关注

    Have you considered using History.js?

    It sounds like you're wanting to essentially use $_GET vars to dictate what's served on the page... kind of. Although it also looks like you're calling in that content via ajax based on this var, so php is mostly irrelevant in this scenario since it would be js parsing the url and deciding what to ajax in. History will do all of this for you. It reads the url as a state and serves as you tell it to. Obviously it's not that simple, but if you read the docs it's pretty clear how to use it. https://github.com/balupton/jquery-history

    评论

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler