douzhi6365 2010-06-19 16:45
浏览 40
已采纳

将PHP与AJAX状态相结合

I have a puzzling problem with trying to make an ajax/static state program. What I am trying to do is allow a static linked app have ajax dynamic urls and everything is kinda fine until a page refresh.

The problem:

PHP Does not see the hash so it only sees the original URI request. So PHP loads the original page but then JQuery (Javascript) replaces that page with the actual one I want after the #. Example:

url: localhost/index.php#!/search

It is fine to navigate to this page but pressing refresh php goes for:

url: localhost/index.php

and then javascript goes for:

url: #!/search

So I actually load two pages...which sucks.

This is a problem that must have occured and I notice facebook have done it to help load times (same reason I wanna do it). From the best I can tell they are able to reliably detect the hash and replace $_SERVER['REQUEST_URI'] with its contents so when you refresh you get localhost/search from localhost/index.php#!/search.

I was wondering if anyone has a little fix for this. I have looked in server side javascript but after a lot of googling I didn't really get a clear picture.

Thanks in advance

  • 写回答

1条回答 默认 最新

  • 普通网友 2010-06-19 17:02
    关注

    The browser itself doesn't even send the hash portion of the URL when it makes a request. You will still need to load two pages. The best you can do is make the initially loaded page a simple static HTML Ajax bootstrap. This way the initial pageload is cacheable, light on resources, and quick to load.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟