简体   繁体   中英

How to redirect/refresh the page after an AJAX call

在AJAX调用之后,我对PHP文件进行了更新,但是我不确定,一旦请求完成,如果页面上的PHP标头位置刷新了我所在的页面,哪种方法更好? ,或在AJAX中完成。刷新页面。

  1. If you are doing Ajax query to other page, then header("location: ...") won't work as it can not refresh current page.

  2. If you are making an Ajax request to the same page, don't do that. Instead submit the form the old school way.

  3. 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.org/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 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM