我有一个样式类似于 ios 的复选框,使用我想更改网站语言的状态。我使用这个代码:langchange.js
$(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();
}
});
});
语言函数.php
<?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;
}
}
?>
我如何使用复选框的状态,保存语言状态并重新加载数据?谢谢