dt3999 2013-10-14 17:42
浏览 442
已采纳

刷新div的内容

I have a div that displays text from a php session:

<div id="sessioncontent">
<?php if (isset( $_SESSION['returntext'])){ echo  $_SESSION['returntext'];} ?>
</div>

I have a javascript method that calls another php script which changes the text within that session variable. At the end of the method, I want the div to refresh so that the new text within the session is echoed. I have tried the following line but it doesnt work:

document.getElementById("sessioncontent").innerHTML = document.getElementById("sessioncontent").innerHTML;
  • 写回答

2条回答 默认 最新

  • dslkchyv673627 2013-10-14 17:46
    关注

    You are replacing content with the same content. I would suggest making an ajax call and then populating your div with the response from the ajax call. Something like this:

    $.ajax({
      url: yourUrl,
      method: 'get', // or 'post'
      success: function (response) {
          $('#sessioncontent').html(response);
      }
      // other ajax options here if you need them
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置