[英]how to send form values to php using AJAX without reloading page?
[英]Reloading PHP FORM using AJAX
在我的Web门户中,我有一个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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.