How to refresh a page inside another page?

I have 2 pages and in the first page, I called another page (second page) via ajax. In the second page there is a form that send via ajax then reload page once. But when the second page refreshes, my first page refreshes too. But I don't want it. I would like only to reload my inner page. Is there a way to reload only internal page? Here is my inner page codes:

$(document).ready(function() {
  $(document).on('click', '.MyForm button[type=submit]', function(e) {
    e.preventDefault() // To make sure the form is not submitted 
    var $frm = $(this).closest('.MyForm');
    console.log($frm.serialize());
    $.ajax(
        $frm.attr('action'), 
        {
          method: $frm.attr('method'),
          data: $frm.serialize(),
          success: function(data) { $(".error").html(data), window.location.reload();}
   
        }
    );
  });
});
.error{width:200px; height:50px;border:1px solid blue;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
  <form class="MyForm" method="post">
    <input type="text" placeholder="name" value="Aynaz" name="a1" />
    <select name="Avg">
      <option value="1">1</option>
      <option value="2">2</option>
    </select>
    <button type="submit">Submit</button>
    <div class="error">Show form success here after page reload</div>
  </form>

window.location.reload() will always reload the whole page. Use load() function same as you are using it in the first place for loading the inner page

 $.ajax(
            $frm.attr('action'), 
            {
              method: $frm.attr('method'),
              data: $frm.serialize(),
              success: function(data) { 
                   $(".error").html(data);
                   $('.div').html('').load('innerpage.htm');// reload the div
              }

            }
        );

从表单中删除method =“post”。


您可以在<iframe>创建内部页面,然后只能重新加载此部分。

链接地址: http://www.djcxy.com/p/94472.html

上一篇: 使用与生命期参数相关的特征类型的生命期错误

下一篇: 如何刷新另一个页面内的页面?