如何在另一个页面内刷新页面?

时间:2016-12-27 06:31:03

标签: javascript php jquery html css

我有2页,在第一页中,我通过ajax调用另一页(第二页)。在第二页中有一个表单,通过ajax发送然后重新加载页面一次。但是当第二页刷新时,我的第一页也会刷新。但我不想要它。我只想重新加载我的内页。有没有办法只重新加载内部页面? 这是我的内页代码:



$(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>
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:4)

window.location.reload()将始终重新加载整个页面。使用与load()功能相同的功能,首先用于加载内页

 $.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
              }

            }
        );

答案 1 :(得分:0)

删除方法=&#34;发布&#34;从形式。

答案 2 :(得分:0)

您可以在 public void assetReturnInitialization(){ System.out.println("Yellow!"); getAstAssetReturnsVO().clearCache(); System.out.println("clearCache Done!"); Row row = getAstAssetReturnsVO().createRow(); row.setAttribute("Stat", "test"); getAstAssetReturnsVO().insertRow(row); System.out.println("getAstAssetReturnsVO Done!"); getAstAssetReturnsVO().setCurrentRow(row); System.out.println("setCurrentRow Done!"); getAstAssetReturnsVO().executeQuery(); System.out.println("executeQuery Done!"); return ; } 中创建内部网页,然后只能重新加载此部分。

相关问题