weixin_33724046 2017-07-31 13:56 采纳率: 0%
浏览 31

通话中的AJAX嵌套内容

I have my website, http://www.yokaproject.com/, i decided to clean it up, im still in the process so if you see that i have mistakes fine, im not done, but i appreciate any comments. The nav at the top displays anchor tags to click and load jquery into the div#container. My problem is that calls are being doubled each time and nesting more and more content, just click art twice in a row. Ive been at this since last Monday so any help is appreciated. Here is my function

$('.header a').on('click', ajaxLoad);

function ajaxLoad(e) {
    e.preventDefault();
    var url = $(this).attr("href");
    var that = $(this);
    that.off('click'); // remove handler
    $.ajax({
      url: url,
      dataType: "html",
      type: "GET",
      cache: false
    }).done(function(data){
        $("#container").html(data);
    });
};

If you want a better look at the html and css you can just visit my site. i plan on putting it up on github in the future once it gets larger but for now its not necessary.

  • you can now view complete code on my website
  • 写回答

2条回答 默认 最新

  • weixin_33701617 2017-07-31 14:01
    关注
    that.on('click', ajaxLoad); // add handler back after ajax
    

    This line of code re-attaches the click handler every time an ajax response comes. And every time you click that you create an ajax request.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据