title: Using jquery ajax, after is:checked, change the website language
body: <p>I have a checkbox styled like on ios, using the state i want to change the language of my website. I use this code:
  langchange.js</p>
  
  <pre><code>$(document).ready(function(){
      $("#langfct").change(function() { 
          if($(this).is(":checked")) { 
              $.ajax({
                  url: 'langfunc.php',
                  type: 'POST',
                  data: { langstate: "fr" }
              });
              alert('fr');
              window.location.reload();
          } else {
              $.ajax({
                  url: 'langfunc.php',
                  type: 'POST',
                  data: { langstate: "en" }
              });
              alert('en');
              window.location.reload();
          }
      }); 
  });
  </code></pre>
  
  <p>langfunc.php</p>
  
  <pre><code>    &lt;?php
      session_start ();
      $valang = $_POST['langstate'];
      $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
      if ($valang == fr){
          include("french.php");
      }elseif ($valang == en) {
          include("english.php");
      } else{
  
      switch ($lang){
          case "fr":
              //echo "PAGE FR";
              include("french.php");//include check session FR
              break;
          case "en":
              //echo "PAGE EN";
              include("english.php");
              break;        
          default:
              //echo "PAGE EN - Setting Default";
              include("english.php");//include EN in all other cases of different lang detection
              break;
      }
      }
      ?&gt;
  </code></pre>
  
  <p>How i can using the state of the checkbox, save the langstate and reload the data ? Thx</p>