[英]How to simulate a button click in AJAX
I am writing a program that should simulate clicking on submit in AJAX, after which the page should asynchronously reload.我正在编写一个程序,它应该模拟点击 AJAX 中的提交,之后页面应该异步重新加载。 I wrote a program, that asynchronously reloads the page, but only if I click on the submit button.我写了一个程序,异步重新加载页面,但前提是我点击提交按钮。
Here is my program:这是我的程序:
$("#form_id").submit(function() {
var str = $(this).serialize();
$.ajax({
type: "POST",
url: "../async_db.php",
data: str,
success: function(html) {
$('#d_id').html(html);
}
});
return false;
});
To reload a page after post data by ajax asynchronously you can use location.reload()
at the end of the submit()
function.要在 ajax异步发布数据后重新加载页面,您可以在submit()
function 末尾使用location.reload()
。
$("#form_id").submit(function() {
var str = $(this).serialize();
$.ajax({
type: "POST",
url: "../async_db.php",
data: str,
success: function(html) {
$('#d_id').html(html);
}
});
return false;
location.reload();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.