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');
       });
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴
  • ¥15 下列c语言代码为何输出了多余的空格