Yii Framework Forum: Ajax Dropdown Unwanted Symbols And Arabic - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Ajax Dropdown Unwanted Symbols And Arabic getting unwanted symbols when ajax updates drop down ( CJSON::encode) Rate Topic: -----

#1 User is offline   ItsYii 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 104
  • Joined: 24-January 12

Posted 30 April 2013 - 07:23 AM

Hi all

I'm using a ajax drop down, one drop down influences the other via ajax call. Everything works but I have some annoying issues.

Here's my code

Controller

public function actionShowcity(){
	
	$dropShows = "<option value='null'>Select Showroom </option>";
 
            // return data (JSON formatted)
            echo CJSON::encode(array(
              'dropShows'=>$dropShows,
             
            ));
if( isset($_POST['city_id'])){


    $data=Showroom::model()->findAll('Title=:Title', 
                  array(':Title'=>(String) $_POST['city_id']));
 
    
				   $data=CHtml::listData($data,'ID','Name');
    foreach($data as $value=>$name)
    {
        echo CHtml::tag('option',
                   array('value'=>$value),CHtml::encode($name),true);
				   
				   
    }
}

   
}


public function actionGotoShow(){
     $data=Showroom::model()->findAll('Name=:Name', 
     array(':Name'=>(String) $_POST['myID']));
	 $this->redirect(array('/showroom'.'/'.$_POST['myID']));

}




index
<?= CHtml::form(); ?>
	<?php
	$options["options"] = array("style" => "color:red;");
	echo CHtml::dropDownList('city_id','', CHtml::listData(Showroom::model()->findAll(),'Title', 'Title'),
array(
"style" => "color:#989898; width:200px; height:30px;",
'empty'=>'Choose a City',
'ajax' => array(
'type'=>'POST', //request type

'url'=>CController::createUrl('showroom/showcity'), //url to call.
'update'=>'#myID', //selector to update
))); 
 
echo CHtml::dropDownList('myID','', array(), array( 
"style" => "color:#989898; width:200px; height:30px;",
'empty'=>'Pick City first',
	'submit'=> '/index.php/showroom/GotoShow'));
?>	
<?= CHtml::endForm(); ?>



So I choose my first drop down, and the message select showroom comes out as

select Showroom<\/option>"} exactly like that with all the symbols.

if I remove the closing option I get select Showroom"} (the comma and curly bracket included)

Also I have 2 version of the site one is arabic so when I do this

$dropShows = "<option value='null'>يبسب";
 
            // return data (JSON formatted)
            echo CJSON::encode(array(
              'dropShows'=>$dropShows,
             
            ));


The result is {" u064a\aU0628\u0633\

Anyone know how I can 1) get rid off the symbols and 2) get the Arabic letters to display?


EDIT: There's a function that converts to UTF8 but it's not working, the drop down stops working

	$dropShows = "<option value='null'>يبسب";
 $dropShows = CJSON::unicodeToUTF8( $dropShows );
            // return data (JSON formatted)
            echo CJSON::encode(array(
              'dropShows'=>$dropShows,
             
            ));


Thanks
0

#2 User is offline   Ganesh Bora 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 41
  • Joined: 30-May 12
  • Location:pune, india

Posted 30 April 2013 - 07:44 AM

please check around json::encode function.
Regards,
Ganesh Bora,Sr. Software Engineer
Pune, India
Cell : 91-8888870703
Social: LinkedIn | Facebook | Google+
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users