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

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)