[英]page will not refresh after a jQuery post
I have a button call this script, so it does the post in the background, but I need to reload the current page to display an updated php query, I realize there was probably a better way in jquery to the query part, but its crunch time, and all I want to do is get a successful page refresh. 我有一个按钮调用此脚本,因此它在后台执行发布,但是我需要重新加载当前页面以显示更新的php查询,我意识到在jquery中可能有更好的方法来查询部分,但是它很紧缩时间,我要做的就是成功刷新页面。 Because the buttons were generated in php, the javascript code is at the end of the body.
由于按钮是在php中生成的,因此javascript代码位于正文的末尾。 I've tried
location.href
, window.location.reload(true);
我试过
location.href
, window.location.reload(true);
, document.write
which only wrote to the page, document.location.href
did nothing. ,
document.write
只写页面, document.location.href
什么也没做。
We are using jQuery/jQuery mobile, I was not on front end dev team, so I'm desperate to get this to work. 我们使用的是jQuery / jQuery mobile,当时我不在前端开发团队中,所以我迫切希望将此工作起来。 to clarify, I need a page refresh after the
$.post()
command, within this code, which does work 为了澄清,我需要在此代码内的
$.post()
命令之后刷新页面,它确实有效
<script type="text/javascript">
$('#reserveBook').click(function () {
var isbn = sessionStorage.getItem('isbn');
$.post(
"../inventory/postpage.php",
{ isbn: isbn }
);
});
</script>
There's no point in using AJAX if you need a page refresh regardless. 如果您需要刷新页面,则使用AJAX毫无意义。 As Dan Bracuk said in his comment, you'd be better off just doing a traditional form submission.
正如Dan Bracuk在评论中所说,最好还是提交传统的表单提交。
However, if you're set on having the page refresh, just add window.location.reload()
in the success handler for your AJAX call: 但是,如果您打算刷新页面,只需在成功处理程序中为您的AJAX调用添加
window.location.reload()
:
$.post(
"../inventory/postpage.php",
{ isbn: isbn },
function(response) {
window.location.reload();
}
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.