Hi guys i have a form in php which can be rendered in many languages.
I’m doing this by using a language class which takes the text from a file on the server and returns it where i need:
$lang = new Lang("en"); and then i use $lang->GetText('my_index') when i display the form on the page.
I want to create a dropdown with languages and when the user selects another language, all the texts displayed by my $lang object to be refreshed with the according values of the selected language.
Normally i would use $_GET[‘country_code’] in my script and do $lang = new Lang($_GET['country_code']); but i want to do this with Ajax so that page doesn’t refresh.
All the Ajax examples i found on the internet were just updating the inner html of a div, select, whatever with the response text received from the php script called in the AjaxRequest but i want to update my $lang variable and redisplay my page so that the language changes.
Thanks a lot 🙂
It seems to me that if you want to ‘redisplay the page’ then you don’t want to be using ajax. Ajax is used to update single aspects of a page in one go, so updating the single div or container is exactly what you want to do.
If you’re using an MVC framework then partial views are great for this as they render single sections of HTML which you can then just drop that in within the callback function on your AJAX call.