Yii Framework Forum: Always Returns Error In Jquery Json Call - Yii Framework Forum

Jump to content

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

Always Returns Error In Jquery Json Call Rate Topic: -----

#1 User is offline   Marcolini 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 16-March 12
  • Location:Portugal

Posted 30 January 2013 - 11:50 AM

Hello everyone.

Im doing an autoComplete Jquery, and on select it calls an action in controller:

views\index.php
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
				'name'=>'test2',
				'source'=> $arrayServices,
				'options'=>array(
					'select' => 'js:function(event, ui){
						$.ajax({
						   type: "GET",
						   dataType: "json",
						   url: "index.php?r=SEMAFOROS/index",
						   data: {FiltersForm: ui.item.value},
						   success: function(data){
								alert('ok');					
						   },
						   error: function (jqXHR, textStatus, errorThrown) {
								alert(textStatus);
								alert(errorThrown);
							},
						 });
					}',
				),
			  ));



in my controller:
if (isset($_GET['FiltersForm']))
{
   $response = array('return', 'msg', 'idk');
   echo CJSON::encode($response);
}


It seems ok to me but the return of jquery call is always an error calling the function of error. What is my problem?
appreciate any tips :)
0

#2 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 30 January 2013 - 02:54 PM

Dear Friend

I checked your code in my localhost , it works well.

$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
                                'name'=>'fruit',
                                'source'=> array("apple","banana","cherry","pineapple","orange"),
                                'options'=>array(
                                        'select' => 'js:function(event, ui){
                                                $.ajax({
                                                   type: "GET",
                                                   dataType: "json",
                                                   url: "'.CHtml::normalizeUrl(array("test/auto")).'",
                                                   data: {"test": ui.item.value},
                                                   success: function(data){
                                                          console.log(data[0]);                                   
                                                   },
                                                   error: function (jqXHR, textStatus, errorThrown) {
                                                                console.log(textStatus);
                                                                console.log(errorThrown);
                                                        },
                                                 });
                                        }',
                                ),
                          ));


TestController.php
public function actionAuto()
{
		//echo $_GET['test'];
		$response = array('return', 'msg', 'idk');
		echo CJSON::encode($response);

}		


It prints
return

in my console.

It also works without declaring dataType.(Jquery make intelligence guess)
In that case use JSON.parse() to get the elements in the data.

Note:You have put ok in single quotes. But anyway it may have thrown php error.

Regards.
0

#3 User is offline   Marcolini 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 16-March 12
  • Location:Portugal

Posted 31 January 2013 - 09:23 AM

thank you for your time seenivasan.
I saw the problem lol. In my controller i had a var_dump to check my action :P didnt know but it screwed up.

[SOLVED]
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