在我的门户网站中,我有一个页面 index.php
其中有<div>
标记使用 AJAX
获取哪些内容。在此<div>
标记页面index2.php
叫做。在页面index2.php
有一种表格应使用 AJAX
提交(无需刷新整个页面,只需刷新 index2.php
)。提交后,index2.php
应该再次调用,但带有来自表单的一些附加参数(超过 POST
)。
问题是因为POST
请求已发送,但看起来像 <div>
的内容( index2.php
) 未更改。这是代码:
index.php
<div id="left_side">
<h3>Toolbar</h3>
</div>
<div id="content">
there will be refreshed index2.php
</div>
......
function doAjax() {
var frm = $('#plotForm1');
$.ajax({
type: frm.attr('method'),
url: frm.attr('action'),
data: frm.serialize(),
success: function (data) {
}
});
}
index2.php
<form id="plotForm1" action="index2.php" onsubmit='doAjax(); return false;' method="post">
....
</form>
最佳答案
index.php
<div id="left_side">
<h3>Toolbar</h3>
</div>
<div id="content">
there will be refreshed index2.php
</div>
......
function doAjax() {
var frm = $('#plotForm1');
$.ajax({
type: frm.attr('method'),
url: frm.attr('action'),
data: frm.serialize(),
success: function (data) {
$('#content').html(data);
}
});
}
index2.php
<form id="plotForm1" action="index2.php" onsubmit='doAjax(); return false;' method="post">
....
</form>
关于javascript - 使用 AJAX 重新加载 PHP FORM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27824699/