douyu9159 2016-06-08 11:44
浏览 80

JQuery + AJAX动态div内容

I'm trying to create a dynamic web page to show some content and change it without reloading the full page but some part of it.

When i press a button of my navigation bar it calls a JavaScript function to change the content of my div tag

<div class="row text-left" id="center"></div>

with this code i put into my div class some text

$('#navHome').click(function(){
    $('#center').html("this is my home");
});

Now i want store a content of every section to reload this every time when i press the button. Something like this:

$('#navHome').click(function() {
   $.get('home.txt', function(data) {
      $("#center").html(data);
   }, 'text');
});

in the home.txt i have store my html code of home section but i have no idea how to make this.

  • 写回答

4条回答 默认 最新

  • dongzongzhi6953 2016-06-08 11:47
    关注

    Try:

    Remove 'text' which you added in last of ajax

    $('#navHome').click(function(){
       $.get('home.txt', function(data) {
          alert(data);
          //process text file line by line
          $('#center').html(data);
       });
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序