javascript - How to redirectrefresh the page after an AJAX call - Stack Overflow

After an AJAX call, I make an update on a PHP file, but I'm not sure, once the request is finished

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
Add a ment  | 

2 Answers 2

Reset to default 4
  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/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)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744208047a4563200.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信