admin管理员组文章数量:1400134
After an AJAX call, I make an update on a PHP file, but I'm not sure, once the request is finished, what is the better way, if a PHP header location on the page who refresh the page where I'm from, or in the AJAX.done refresh the page.
After an AJAX call, I make an update on a PHP file, but I'm not sure, once the request is finished, what is the better way, if a PHP header location on the page who refresh the page where I'm from, or in the AJAX.done refresh the page.
Share Improve this question edited Jul 24, 2014 at 16:48 code-jaff 9,3204 gold badges38 silver badges56 bronze badges asked Jul 24, 2014 at 15:51 eduardo aeduardo a 1504 silver badges18 bronze badges 1- 4 If you're going to refresh the page, why use ajax, just do a form submit instead. Also, when using ajax, setting a PHP header wouldn't really work. – adeneo Commented Jul 24, 2014 at 15:53
2 Answers
Reset to default 4If you are doing Ajax query to other page, then
header("location: ...")
won't work as it can not refresh current page.If you are making an Ajax request to the same page, don't do that. Instead submit the form the old school way.
If you are making an Ajax request to other page that does something essential for you and then you want to refresh the current page then use the given JavaScript code in AJAX.done.
If you want to preserve cache and reload(soft reload) which is a better way, use:
location.reload(false);
However If you have requirement to clear cache and reload(hard reload), use:
location.reload(true);
Hope this helps.
You can find more detail about location.reload
here: https://developer.mozilla/en-US/docs/Web/API/Location.reload
If you want to refresh the whole page then don't even use an ajax request, submit your form, and php redirect will be fine.
If you want to refresh a part of the page (for instance the content of a div
), then you should do it client-side (in Ajax.done
)
本文标签: javascriptHow to redirectrefresh the page after an AJAX callStack Overflow
版权声明:本文标题:javascript - How to redirectrefresh the page after an AJAX call - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744208044a2595285.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论