简体   繁体   English

如何动态更改语言?

[英]How can I change language dynamically?

I'm a newbie with jquery mobile, php and javascript. 我是jquery mobile,php和javascript的新手。

I want my users to be able to click a button (javascript on click event) that will execute a "setlocale()" php command. 我希望我的用户能够单击一个按钮(单击事件中的javascript),该按钮将执行“ setlocale()” php命令。 This will allow the current page to be dynamically re-displayed in a different language (French). 这将允许当前页面以其他语言(法语)动态重新显示。

I understand that javascript is client side and php is server side and cannot communicate variable values directly. 我了解到javascript是客户端,而php是服务器端,无法直接传递变量值。

So, is linking to the current page with $_POST['language'] a possible way way to do this or is there another method? 那么,使用$ _POST ['language']链接到当前页面是执行此操作的一种可能方法,还是有另一种方法?

Thanks 谢谢

Mainly when your client-side page is displayed the server-side .php script has already ran and is finished. 主要是在显示客户端页面时,服务器端.php脚本已经运行并完成。 Setting anything for PHP does not make the page change itself. 为PHP设置任何内容都不会更改页面本身。 You woulhd have to employ some sort of AJAX content loading and forward a language variable to the .php serving the AJAX. 您将必须采用某种AJAX内容加载方式,并将语言变量转发给服务AJAX的.php。 Rather use $_GET in this case. 在这种情况下,请使用$ _GET。 What you do with it in your .php would need further investigation in your code... 您需要在您的.php文件中进行进一步的调查...

Use XMLHTTPRequest to submit data to a PHP file and get the responses. 使用XMLHTTPRequest将数据提交到PHP文件并获取响应。 There are plenty of tutorials on the internet about it, for example on W3Schools or Wikipedia . 互联网上有很多关于它的教程,例如W3SchoolsWikipedia

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM