php - A refresh command after a jquery ajax request is breaking the script in Firefox -


so here's thing: i'm working on system update language of website after click on item. works great on chrome , internet explorer, desktop (windows 8.1) or mobile on firefox (desktop , mobile) doesn't work if have kind of command refresh page. works on firefox if remove command , refresh page myself.

i'm relying on session variables need refresh, right?

this looks @ moment:

<head>     <script type="text/javascript" src="../scripts/global/jquery-2.1.3.min.js"></script>     <script>         $(document).on("click",".button",function(){             var language = $(this).attr("id");             $.post("changelanguage.php", {"language": language});         });     </script> </head> <body>     <a class="button" id="en">en</a>     <a class="button" id="de">de</a>     <a class="button" id="pt">pt</a>     <br>     <span id="test">         <?php              if (isset($_session["displaylanguage"]))             {                 echo $_session["displaylanguage"];             }             else             {                 echo $_session["browserlanguage"];             }          ?>     </span> </body> 

i've tried refreshing with:

location.reload(); location.reload(true); window.location.href=window.location.href; history.go(0); 

and breaks script in firefox not others.

i'm out of ideas i'm pretty new i'm hoping guys can help.

thanks in advance.

edit: update: upon closer inspection while seem page indeed refreshing, <span> content isn't updating, problem must in firefox isn't letting bit of php code run again, instead of breaking script.

edit: update 2 if page refreshes on it's own following script tells to, regular refresh doesn't update update <span> content have assume doesn't break whole script @ least .post request update session variable doesn't seem working while refresh request present.

i think issue when attempt refresh. should wait success $.post(). (untested, comment if there issue)

<head>     <script type="text/javascript" src="../scripts/global/jquery-2.1.3.min.js"></script>     <script>         $(document).on("click",".button",function(){             var language = $(this).attr("id");             $.post("changelanguage.php", {"language": language})             .error(function(jqxhr, errorstr){                 console.log("ajax error: " + errorstr);                 return false;             })             .done(function(){                 alert("success - reloading.");                 location.reload();             })             .fail(function(){                 console.log("ajax failed.");                 return false;             });         });     </script> </head> <body>     <a class="button" id="en">en</a>     <a class="button" id="de">de</a>     <a class="button" id="pt">pt</a>     <br>     <span id="test">         <?php              if (isset($_session["displaylanguage"])) {                 echo $_session["displaylanguage"];             } else {                 echo $_session["browserlanguage"];             }          ?>     </span> </body> 

also, advise using firebug. add-on allows set console log persist. find hugely valuable ajax testing. failed ajax causes link execute. may not catch error or display in console. having persist allow execute , still console note.


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -