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
)
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744208047a4563200.html
评论列表(0条)