Ajax call from phonegap to login in Yii fails

Ajax call from phonegap to login in Yii fails

I'm doing my first phonegap app and I run into login problem. I have an appLogin action in the site controller and I know it reaches the controller's action and logs in - anyway the credentials get validated and login is successful. But the ajax call in app fails to get response. If I comment out the login part and just echo something the ajax call is succesful and receives the response. I know I'm probably missing something basic regarding authentication. What is it?

  1. BusinessBox.prototype.serLogin = function(){
  2. var me = this;

  3. alert("ajax login "+me.credentials.loginform.username);

  4. $.ajax({
  5. type: "POST",
  6. url: serverActions.appLogin(),
  7. dataType: "json",
  8. data: me.credentials
  9. }).done(function( obj ) {
  10. alert(obj);
  11. if(obj) {
  12.    me.loggedIn = true;
  13.    alert(obj);
  14. } else {
  15.    me.loggedIn = false;
  16.    alert("not logged in");
  17. }
  18. }).fail(function(err){
  19. alert("error log in");
  20. }); 

  21. }


and here is the php

  
  1. public function actionAppLogin() { $model=new LoginForm; // if it is ajax validation request if(isset($_POST['ajax']) && $_POST['ajax']==='login-form') { echo CActiveForm::validate($model); Yii::app()->end(); } // collect user input data if(isset($_POST['loginform'])) { $request = $_POST['loginform']; $model->attributes=$request; if($model->validate() && $model->login()){ //it reaches here echo 111; } else { echo 444; } } else { echo 222; } }