weixin_33713503 2015-06-13 02:00 采纳率: 0%
浏览 27

Ajax加载动态页面

HTML index.php

<a class="cart-icon" href="cart"></a>
<div class="content"></div>

Ajax load content from load-content/cart.php

$(document).ready(function(){
   $(document).on('click', '.cart-icon', function(e){
       e.preventDefault();
       var page = $(this).attr("href");
       $('.content').load('load-content/'+page+'.php');
   });
});

This code will load content from cart.php but not update a url so when i refresh the page the content in that div dissapear. I want it when i refresh page it will not dissapear and also update url.

For example: default url: index.php and when i press an a tag it will load content from cart.php and update url to index.php/load-content/cart.php

  • 写回答

1条回答 默认 最新

  • weixin_33736832 2015-06-13 02:20
    关注

    You need a persistent storage of some kind. Anything you load into the DOM of a page is temporary. You might simply do the same thing that you're doing here on document load:

    $(document).ready(function(){
       $('.content').load('load-content/'+page+'.php');
       $(document).on('click', '.cart-icon', function(e){
           e.preventDefault();
           var page = $(this).attr("href");
           $('.content').load('load-content/'+page+'.php');
       });
    });
    
    评论

    报告相同问题?

    悬赏问题

    • ¥15 存储过程或函数中的结果集类型变量如何使用。
    • ¥80 关于海信电视聚好看安装应用的问题
    • ¥15 vue引入sdk后的回调问题
    • ¥15 求一个智能家居控制的代码
    • ¥15 ad软件 pcb布线pcb规则约束编辑器where the object matpcb布线pcb规则约束编辑器where the object matchs怎么没有+15v只有no net
    • ¥15 虚拟机vmnet8 nat模式可以ping通主机,主机也能ping通虚拟机,但是vmnet8一直未识别怎么解决,其次诊断结果就是默认网关不可用
    • ¥20 求各位能用我能理解的话回答超级简单的一些问题
    • ¥15 yolov5双目识别输出坐标代码报错
    • ¥15 这个代码有什么语法错误
    • ¥15 给予STM32按键中断与串口通信