【发布时间】:2017-05-11 10:38:27
【问题描述】:
我有 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>
【问题讨论】:
-
内页?您如何将其加载到您的“父页面”中?框架?请澄清
-
您能否将整个文档显示为 sn-p,可能在 jsfiddle 中?
-
@anu 在 div 中使用简单的 onclick 事件加载页面:$('.div').load('innerpage.htm');
-
-
那你为什么不再试一次呢。而不是
window.location.reload();使用$('.div').html('').load('innerpage.htm');
标签: javascript php jquery html css