javascript - Reload page after click on <a> to get new data from PHP -
i'm writing multilingual web , logic next:
- by default there "lang.tmp" file default data "eng".
when index.php loads takes data "lang.tmp" , sets default language loading data lang.php:
include("lang/".file_get_contents("lang.tmp").".php");
if user wants change language, clicks on link created php, rewrites data in "lang.tmp":
include("lang/languages.php"); $i=0; while (list($key, $value) = each($languages)) { echo '<li class="lang"><a href="index.php?'.$key.'"><div id="langbox">'.$value.'</div></a></li>'; if ($_server['query_string'] == $key) { $fp=fopen("lang.tmp","w"); fwrite($fp,basename($key)); fclose($fp); }
so! problem is: after rewriting "lang.tmp" file need reload page same "index.php" address new type of language.
i've tried
header("location: index.php");
and doesn't work because url same, i'm getting error:
warning: cannot modify header information - headers sent.
i tried javascript:
$("div #langmenu").click(function() { location.reload(); console.log ("clicked!"); });
but doesn't worked either. page reloads new language after second click on link, that's not needs ))
would kind link i'm wrong or other options reload page in situation.
- the
header
redirect should work, error means text has been shown (you can make call when page loading, not once you've sent content). - the logic flawed in single user change language entire site.
- why not make
<a>
link page in first place?
Comments
Post a Comment