Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8028189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:03:46+00:00 2026-06-05T00:03:46+00:00

Refer to my code below, when user click on en button, the content will

  • 0

Refer to my code below, when user click on en button, the content will be changed to English, while clicking tw button, the content will be changed to Chinese.

However, the page will be refreshed each time when user click either en or tw button. I want to ask how can I implement AJAX content update in this case?

The result is when user click either en or tw button, the page won’t be refreshed to change the content language.

Thanks

I have refer to Yii docs here, but seem that it is not appropriate for my case

C:\wamp\www\website\protected\views\site\index.php

<?php
$lang = isset($_GET["lang"]) ? $_GET["lang"] : "en_uk";
$lang = $lang == "en" ? "en_uk" : "zh_tw";

Yii::app()->setLanguage($lang);
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
    <input type="submit" value="en" name="lang" />
    <input type="submit" value="tw" name="lang" />
</form>

<div class="main">
    <?php echo Yii::t(Yii::app()->controller->id, "Causeway Bay"); ?>
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T00:03:49+00:00Added an answer on June 5, 2026 at 12:03 am

    Best practice is to reload the page in these cases, because usually you have to update so much, that it is just not worth it.

    That said, CHtml’s ajaxSubmitButton is the cleanest way to implement this, because you can map every event of your call very easily. It looks something like this:

    <?php 
    echo CHtml::ajaxSubmitButton('en', CHtml::normalizeUrl(array('site/changeLanguage')),
    array(
        'error'=>'js:function(){
            alert("error");
        }',
        //if you add a return false in this, it will not submit. 
        'beforeSend'=>'js:function(){
            alert("beforeSend");                                            
        }',
        'success'=>'js:function(data){
            alert("success, data from server: "+data);
        }',
        'complete'=>'js:function(){
            alert("complete");
        }',
        //'update'=>'#where_to_put_the_response',
    )
    );
    ?>
    

    You don’t have to use every parameter of course. The update parameter can update a HTML tag instantly.

    EDIT:
    This can be done easily if you use the controller’s renderPartial method, for instance in your site controller if you have the action responsible for the index.

    public function actionIndex(){
       //get variables, etc
    
    
       if(Yii::app()->request->isAjaxRequest) {
          $lang = $_POST['nameOfSubmit'];
    
       }else {
          //...
       }
       //if the 3rd parameter is true, the method returns the generated HTML to a variable
       $page = $this->renderPartial('_page', array(/*parameters*/ ), true); 
       echo $page; 
    }
    

    And then, in your view file you can simply have

    <?php echo CHtml::ajaxSubmitButton('en', CHtml::normalizeUrl(array('site/index')),
    array('update'=>'#content_div',));?>
    

    and

    <?php echo CHtml::ajaxSubmitButton('tw', CHtml::normalizeUrl(array('site/index')),
        array('update'=>'#content_div',));?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please refer to the below jsfiddle code snippet: http://jsfiddle.net/JLXs5/3/ When the user clicks here,
Please refer this fiddle http://jsfiddle.net/qJBhD/4/ Here while clicking the question1, the answer1 is displayed.
Please refer to the code below, when I comment in either of the commented
Please refer to the Java code below: class Base{ Base(){ System.out.println(Base Constructor); method(); }
Refer below code public void acquire(){ synchronized(a){ print(acquire()); try{ //Thread.sleep(5000); synchronized(this){ wait(5000); } print(I
please refer to the code below. $dArr = '<script>document.write(volunteerDist);</script>'; $dArr gets the value of
Please refer to my code below. When optimization in IAR MSP430 compiler is set
How can I enumerate through an IDictionary? Please refer to the code below. public
Please refer the below code. I want the boxes for Blue and all other
Please refer code below i m learning jquery and i want to display tag

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.