-1

I set a cookie with Javascript. I have a input type checkbox that will switch theme on the website from normal to classic version and so will the cookie name. My backend is PHP. I want to access the newly changed value when clicking the checkbox with PHP, so naturally i want to reload the page so PHP can pick up the new value. Here comes the problem, all the suggestions out there suggest this:

location.reload(true);

But my Visual Studio Code says this is deprecated and indeed, it does not work indeed.

I checked MDN - [https://developer.mozilla.org/en-US/docs/Web/API/Location/reload][1] and it says that i should not pass any params and just use

location.reload(); 

And yes, using this reloads the page but it seems like it doesn't reload it by requesting the page from the server because my PHP does not pick up the new value. Only when i hit the refresh button manually, it does. And MDN says "The Location.reload() method reloads the current URL, like the Refresh button." which doesn't seem true.

So what can i do here?

Djongov
  • 195
  • 2
  • 13
  • I am really interested if before deprecation location.reload(true); was the thing i need, and if yes, surely there must be an alternative. I am very aware of the difference between client/server side. I also don't think ajax will help me. I want to reload the whole page and get the new theme. A lot will depend on this. – Djongov Apr 25 '21 at 20:50
  • You may want to check this possible duplicate then, since you want to do a force reload, and that flag is now deprecated: https://stackoverflow.com/questions/55127650/location-reloadtrue-is-deprecated – Daedalus Apr 25 '21 at 21:09

1 Answers1

0

You can try reloading page from php using:

header("Location: *your directory*");

If you set the same page you were it will just reload.