【问题标题】:how to refresh the div content without the page reloads如何在不重新加载页面的情况下刷新 div 内容
【发布时间】:2018-10-12 10:55:08
【问题描述】:

我在单击保存时将模态框保存在临时页面中,并且模态框必须关闭值应该显示在 div 内容中。现在它工作正常但是当页面重新加载时内容正在显示。我不想重新加载页面

html代码:

<div class="content">

  <?php if($load_data): ?>

    <?php foreach($load_data as $data): ?>
      <div class="row modal_bg">
        <div class="col-md-3">
          <span class="jd_name"><?php echo $data->first_name; ?></span>
          <span class="jd_name" ><?php echo $data->last_name; ?></span>
          <p class="loc"><?php echo $data->location; ?></p>
        </div>

      </div>
    <?php endforeach; ?>
  <?php endif; ?>

</div>

ajax 代码:

jQuery.ajax(
  {
    type: "POST",
    url: "<?php echo base_url(); ?>" + "page/datapage/",
    data: formData,
    processData: false,
    contentType: false,
    success: function(res) 
      {
        $('#myModal').modal('hide');
        console.log(res);
        if(res)
        {

          url:"<?php echo base_url(); ?>page/datapage/<?php echo $per->id;  ?>";

        }
      },
    error: function(errResponse) 
      {
        console.log(errResponse);
      }
  });

如何解决这个问题,无需重新加载页面我想显示内容。谁能建议我怎么做。

【问题讨论】:

  • 研究.html()
  • @ThisGuyHasTwoThumbs 完全正确。
  • 如果这是关于从源更新数据,你可以看看 RxJS 并使用Subscribers
  • 你应该使用 .html() 标签
  • 1. url:"&lt;?php echo base_url(); ?&gt;page/datapage/&lt;?php echo $per-&gt;id; ?&gt;"; 应该是什么? 2.如果您提交表单并且不想重新加载页面,则必须禁止标准提交:e.preventDefault

标签: javascript php jquery ajax twitter-bootstrap


【解决方案1】:

你需要使用html();

success: function(res) 
      {
$('#yourTargetId').html(res);

【讨论】:

  • console.log(res) 输出了什么;
  • 显示这个页面 " + "页面/数据页/"
  • Rahul 在这里所说的是正确的。请注意 $('#yourTargetId').html(res);从 AJAX url 中指定的文件中打印出每个 html 内容。因此,如果您需要它显示特定的内容,您只需在该文件中构建它,它就会在成功时加载到目标元素中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-19
  • 1970-01-01
  • 2016-09-04
  • 1970-01-01
  • 2023-04-06
  • 2013-08-20
相关资源
最近更新 更多