【问题标题】:Load and override current page url and contents with jQuery Ajax使用 jQuery Ajax 加载和覆盖当前页面 url 和内容
【发布时间】:2021-02-02 19:14:18
【问题描述】:

我的 index.php 上有一个产品列表,在单击产品名称时,我想通过加载 product_details.php 页面及其内容和 url 来覆盖 index.php 内容和 url,而无需重新加载页面。

我使用下面的代码覆盖了 url,但我不知道如何加载内容。

$(document).on("click", ".view", function(e) { 

  e.preventDefault();

  var url = $(this).attr(href);

  history.pushState('obj', 'Product Details', url); 


 }); 

这是我想要的一个例子

www.flutterwave.com/store/sativamerch

【问题讨论】:

  • 研究pushstatehistory.pushState(null, null, url);
  • 签出我的代码。我编辑了它。

标签: jquery ajax


【解决方案1】:

你可以做这样的事情......

$(document).on("click", ".view", function(e) {

       e.preventDefault();
    
       var url = $(this).attr("href");
  

    $('#loader').css("display","inline-block"); // display's a loader while loading 
    
        
     setTimeout(function() {  
    
            $("#products").load(url + " #details", function() {
    
       history.replaceState('obj', 'Product_Details', url);  });
          
        }, 2000);
       
    });
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-21
    • 2014-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-15
    • 1970-01-01
    • 2011-05-22
    相关资源
    最近更新 更多