Error when using ajax requests

Hi all, i'm trying to make remote form validation. For example - check if username already exists.

i've CAction RegistrationAction



<?php





class RegistrationAction extends CAction


{


    public function run()


    {


        if(isset($_POST['action'])) $this->checkform();


        else $this->showform();


    }





    private function checkform()


    {


        echo "test";


    }





    private function showform()


    {


       ...................


so, form is shown, but when i make ajax request to this action i get this error

Fatal error:  Call to a member function getScriptFile() on a non-object in E:homevanixnew


wwwsystemwebCThemeManager.php on line 95

what i'm doing wrong?

It complains that Yii::app()->getRequest() is null, which shouldn't. How are you using the action?

I've registration form. When user fills username field jquery sends post request to this action

This problem doesn't appear when i use "buildin" function, for example - ajaxbutton… only when i use my own javascript

Could you please provide the relevant view code and also the code in checkform (this is the problematic ajax action, right?)

Well, here is a better example of my problem.

AdminCP login. I use extjs to make my admin panel.

so, here is my view (at this moment, for debug, i don't use assets)



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">


<html>


    <head>


        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />


		<meta http-equiv="cache-control" content="no-cache">


        <meta http-equiv="pragma" content="no-cache">


        <link rel="stylesheet" type="text/css" href="/resources/css/ext-all.css">


        <link rel="stylesheet" type="text/css" href="/resources/css/xtheme-gray.css">


        <link rel="stylesheet" type="text/css" href="/resources/css/admin.css">


        <title>DigitalCode AdminCp</title>


    </head>


    <body>


        <div id="loading-mask" style="width:100%;height:100%;background:#f1f1f1;position:absolute;z-index:20000;left:0;top:0;">


            &#160;


        </div>


        <div id="loading">


            <div class="loading-indicator">


                <img alt="Loading..." src="/resources/images/default/grid/loading.gif" style="width:16px;height:16px;vertical-align:middle"/>&#160;<span id="load-status">Загрузка основной системы</span>


                <div style="font-size:10px; font-weight:normal;margin-top:15px;">


                    Copyright &copy; Vanix Dot Net 2008


                </div>


            </div>


        </div>





        <script src="/resources/ext/jquery.js?<?php echo date('dmY',filemtime('resources/ext/jquery.js'));?>" type="text/javascript">


        </script>


        <script src="/resources/ext/ext-jquery-adapter.js?<?php echo date('dmY',filemtime('resources/ext/ext-jquery-adapter.js'));?>" type="text/javascript">


        </script>


        <script src="/resources/ext/ext-all-debug.js?<?php echo date('dmY',filemtime('resources/ext/ext-all-debug.js'));?>" type="text/javascript">


        </script>


        <script src="/resources/js/admin/namespaces.js?<?php echo date('dmY',filemtime('resources/js/admin/namespaces.js'));?>" type="text/javascript">


        </script>


        <script src="/resources/js/admin/app.lang.ru.js" type="text/javascript">


        </script>


        <script type="text/javascript">


            var BaseHref = '/backend/';





            Ext.BLANK_IMAGE_URL = '/resources/images/default/s.gif';


            App.settings = Ext.decode('<?php echo $settings; ?>');


            App.fullscreen = false;


            App.Languages = [];


            App.Languages.push(["ru", "Russian"]);


        </script>


        <script src="/resources/js/admin/app.js" type="text/javascript">


        </script>


        <script src="/resources/js/admin/app.dialog.login.js" type="text/javascript">


        </script>


        <script src="/resources/js/admin/common.js" type="text/javascript">


        </script>


        <script type="text/javascript">


            Ext.QuickTips.init();


        </script>


        <script type="text/javascript">


            Ext.get("load-status").update("Загрузка диалога входа в систему");


        </script>


        <script type="text/javascript">


            Ext.onReady(App.mainLayout.login, App.mainLayout);


        </script>


        <div style="position:absolute;right:10px;bottom:10px">


            Powered by DigitalCode v1.0


        </div>


    </body>


</html>


here is part of backend controller

<?php





class BackendController extends CController


{


	public function actions()


	{


	}





	public function actionIndex()


	{


        $this->widget('application.extensions.backend.backend');


	    $data["settings"] = "{"name":"","user_id": 0,"max_rows_list":"30","language":"ru","first_weekday":"1"}";


		$this->renderPartial('adminlogin', $data, false, true);


	}


    


    public function actionLogin()


    {


        $config['host'] = '/backend/';


        $settings['config'] = $config;


        $settings['name'] = '';


        $data['success'] = TRUE;


        $data['settings'] = $settings;        


        


        echo CJSON::encode($data);


    }


}

and my ajax login function



                        Ext.Ajax.request({


                            url: BaseHref + 'login/',


                            params: {


                                task: 'lost_password',


                                email: text


                            },


                            callback: function(options, success, response){


                                if (!success) {


                                    Ext.MessageBox.alert(App.lang['strError'], App.lang['strRequestError']);


                                }


                                else {


                                


                                    var responseParams = Ext.decode(response.responseText);


                                    if (!responseParams.success) {


                                        Ext.MessageBox.alert(App.lang['strError'], responseParams.feedback);


                                    }


                                    else {


                                        Ext.MessageBox.alert(App.lang['strSuccess'], responseParams.feedback);


                                    }


                                }


                            }


                        });


here is error



POST http://vanixnew/backend/login/ 400 CHttpException


Fatal error:  Call to a member function getScriptFile() on a non-object in E:homevanixnew


wwwsystemwebCThemeManager.php on line 95


this problem is very actual, because i'll use ajax in all admin functions…

I don't understand. Please use the code you are showing here to explain the problem because your original problem description doesn't refer to these code.

Ok, i'll try.

  1. i want to use ajax requests in my project admin panel. i'm using extjs with jquery.

  2. this code refers to admin panel login window.

  3. here is simple ajax submit form. when i use GET method - it works, but when POST - i get error.

I mean, when using ajax request with post method - i always get

Call to a member function getScriptFile() on a non-object in E:homevanixnew


wwwsystemwebCThemeManager.php on line 95

this error apears only if i use my own ajax requests. if i use buildin ajaxsubmit button - i've no errors on post request. maybe i've lost some variables?

1)The problem is not in AJAX. How about the stack trace?

2)You are trying to debug with lots of irrelevant code. Which query goes to server that causes this? If the query is http://vanixnew/backend/login/, then could you show the full backend controller file? How about the query http://vanixnew/inde…=backend/login? Just manually type it in the browser and see the result.

  1. Quick note - you’re using $this->widget() in controller. This is mainly used in views. Are you sure you’re achieving correct result with it? If so - just ignore this note :)

А еще, можно спрашивать в русской части форума :) И ответ приходит не слишком медленно, я стараюсь почти сразу.

  1. there is no stack trace… only this error

  2. this page (http://vanixnew/backend/login/) opens normaly.

http://vanixnew/inde…r=backend/login opens too. but doesn’t work with post request.

  1. ignoring  ;D

П.С.

Да че-то приперло тут спрашивать, вот и спрашиваю :)

Very strange… I didn't use ExtJS for long, I don't remember if request type should be set explicitly. Seems there is GET if no params and POST if there are params. How about setting request type to GET explicitly and giving a try?

Are you sure you don't have any other code in BackendController::login() or filters? Could you also post the application config?

And one more thing. In your JS code:



Ext.Ajax.request({


                            url: BaseHref + 'login/',


                            params: {


                                task: 'lost_password',


                                email: text


                            },


What BaseHref is?

BaseHref is backend url, so full ajax request url is '/backend/login/'

i try to make post request with jquery in firebug - i get this error again.

i've just created clear controller with index action. and post request to it failed.

Very strange, I've created ExtJS+Yii application and used POST requests there - it worked fine. I also use POST requests in other applications - it's fine.

OK, how about uploading your app here and giving setup instructions?

And could you show the application config anyway?

here is config



<?php


return array(


	'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',


	'name'=>'Vanix Net',


    'theme'=>'vanixnew',


    'language'=>'ru',


    


	'preload'=>array('log'),





	'import'=>array(


		'application.models.*',


		'application.components.*'


	),





	'components'=>array(


		'log'=>array(


			'class'=>'CLogRouter',


            'routes'=>array(


				array(


					'class' => 'CWebLogRoute',


					'levels' => 'trace, info, error, warning',


					'categories' => 'system.*',


					'showInFireBug' => false


				),


                array(


                    'class'=>'CFileLogRoute',


                    'levels'=>'trace, info',


                    'categories'=>'system.*',


                )


            )


		),


		'urlManager'=>array(


            'urlFormat'=>'path',


			'urlSuffix'=>'.html', 


			'showScriptName'=>false,


            'rules'=>array(


				''=>'news/list',


				'backend'=>'backend/index',


				'backend/login'=>'backend/login',


				'login'=>'users/login',


				'registration'=>'users/registration',


                'users/<user:[a-zA-Z0-9_-]+>'=>'users/detail',


		        'archive/<day:d{2}><month:d{2}><year:d{4}>'=>'news/archive',                


		        '<category:[a-zA-Z0-9_-]+>'=>'news/category',


		        '<category:[a-zA-Z0-9_-]+>/<news:[a-zA-Z0-9_-]+>'=>'news/full',


		        '<category:[a-zA-Z0-9_-]+>/<news:[a-zA-Z0-9_-]+>/add'=>'comments/create'


            )


        ),


		'user'=>array(


			'allowAutoLogin'=>true,


			'loginUrl'=>array('users/login'),


		),


        'db'=>array(


            'class'=>'CDbConnection',


            'connectionString'=>'mysql:host=localhost;dbname=vanixnew',


            'username'=>'vanixnew',


            'password'=>'vanixnew',


			'charset'=>'utf8'


			//'schemaCachingDuration'=>'30'


        ),


        'authManager'=>array(


            'class'=>'CDbAuthManager',


            'connectionID'=>'db'


        ),


        'request'=>array(


            'enableCsrfValidation'=>flase,


            'enableCookieValidation'=>false


        ),





        /*'cache'=>array(


            'class'=>'CMemCache',


            'servers'=>array(


                array(


                    'host'=>'127.0.0.1',


                    'port'=>11211,


                    'weight'=>60


                )


            )


        ),*/








	),





	'params'=>array(


		'adminEmail'=>'webmaster@example.com' ,


		'keywords'=>'',


		'commentNeedApproval'=>false,


		'useAjax'=>true


	)


);


i'll upload it in few moments

the problem is out… i hate denwer  >:(

Yes, me too, so I use XAMPP :)

What was the problem?

First of all - i've many errors in my code, that denwer doesn't show)))

about the problem - it apears if i set this in my config



        'request'=>array(


            'enableCsrfValidation'=>true,


            'enableCookieValidation'=>true


        ),


Well, i can't find how to use ajax request with enableCsrfValidation enabled.

It is possible to get this random number that is generated for form?