javascript - Login page with ionic, transaction errors -


i have issue, beginner this. login page ionic, error says :

referenceerror: res not defined
@ object.loginuser (http://localhost:8100/js/services.js:41:25)
@ scope.$scope.dologin (http://localhost:8100/js/controllers.js:23:22)
@ fn (eval @ compile (http://localhost:8100/lib/ionic/js/ionic.bundle.js:27638:15), :4:212)
@ http://localhost:8100/lib/ionic/js/ionic.bundle.js:65427:9
@ scope.$eval (http://localhost:8100/lib/ionic/js/ionic.bundle.js:30395:28)
@ scope.$apply (http://localhost:8100/lib/ionic/js/ionic.bundle.js:30495:25)
@ htmlanchorelement. (http://localhost:8100/lib/ionic/js/ionic.bundle.js:65426:13)
@ defaulthandlerwrapper (http://localhost:8100/lib/ionic/js/ionic.bundle.js:16787:11)
@ htmlanchorelement.eventhandler (http://localhost:8100/lib/ionic/js/ionic.bundle.js:16775:9)
@ triggermouseevent (http://localhost:8100/lib/ionic/js/ionic.bundle.js:2953:7)

error trans [object sqltransaction]

my controllers.js :

.controller('loginctrl', function($scope, loginservice, $ionicpopup, $state) {         $scope.data = {};      $scope.dologin = function() {         username = $scope.data.user;         password = $scope.data.pwd;         alert(username);         loginservice.loginuser($scope.data.user, $scope.data.pwd).success(function(data) {             $state.go('tableaudebord');         }).error(function(data) {             var alertpopup = $ionicpopup.alert({                 title: 'login failed!',                 template: 'please check credentials!'             });         });     } }) 

my services.js

.service('loginservice', function($q) {     return {         loginuser: function(name, pw) {             var deferred = $q.defer();             var promise = deferred.promise;              var self = this;             db.transaction(function(tx) {                 // running sql query                 alert(username);                 alert(password);                 tx.executesql("select username, password users username = ?", [username], function(tx, res) {                     var len = res.rows.length;                     // (var = 0; < len; i++) { // loop many times there row results                     alert(res.rows.item(0).username + ' : ' + res.rows.item(0).password);                      //   //alert( res.rows.item(i).username +' : '+ res.rows.item(i).password ); // showing results                     // }                     if (username == res.rows.item(0).username && password == res.rows.item(0).password) {                         deferred.resolve('bienvenue ' + username + '!');                         alert("seccess");                     } else {                         deferred.reject('informations erronées.');                     }                 }, function(e) {                     console.log("error trans " + e);                     alert("error sql: " + e.message);                 });             });              if (name == res.rows.item(0).username && pw == res.rows.item(0).password) {                 deferred.resolve('welcome ' + name + '!');             } else {                 deferred.reject('wrong credentials.');             }             promise.success = function(fn) {                 promise.then(fn);                 return promise;             }             promise.error = function(fn) {                 promise.then(null, fn);                 return promise;             }             return promise;         }     } }); 

i grateful if u me, or if have suggestion how verify login

**

1st edition

**

i've changed method controller became :

.controller('loginctrl', function($scope, loginservice, $ionicpopup, $state) {         $scope.data = {};      $scope.dologin = function() {         username = $scope.data.user;         password = $scope.data.pwd;                   var self = this;     db.transaction(function(tx) {                         // running sql query          tx.executesql("select username, password users username = ?", [$scope.data.user], function(tx, res) {         var len = res.rows.length;         // (var = 0; < len; i++) { // loop many times there row results             alert(username);              alert( res.rows.item(0).username +' : '+ res.rows.item(0).password );          //   //alert( res.rows.item(i).username +' : '+ res.rows.item(i).password ); // showing results         // }         if (username == res.rows.item(0).username && password == res.rows.item(0).password) {                 deferred.resolve('bienvenue ' + username + '!');                 alert("seccess");                 $state.go('tableaudebord');             } else {                 var alertpopup = $ionicpopup.alert({                 title: 'login failed!',                 template: 'please check login informations!'             });             }       }, function(e) {         alert("error trans " + e);         var alertpopup = $ionicpopup.alert({                 title: 'login failed!',                 template: 'please check sql trans! '             });       });     });     } }) 

app.js

var username = null; var db = null; angular.module('app', ['ionic', 'app.controllers', 'app.routes', 'app.services', 'app.directives'])  .run(function($ionicplatform) {   $ionicplatform.ready(function() {     // hide accessory bar default (remove show accessory bar above keyboard     // form inputs)     if (window.cordova && window.cordova.plugins && window.cordova.plugins.keyboard) {       cordova.plugins.keyboard.hidekeyboardaccessorybar(true);       cordova.plugins.keyboard.disablescroll(true);     }     if (window.statusbar) {       // org.apache.cordova.statusbar required       statusbar.styledefault();     }              /* database integration */               db = window.opendatabase("utilisateurs.db", "1.0", "utilisateurs.db", 200000);           //alert("sqliteplugin not loaded");    }); }) 

and when start android emulator got error transaction

alert("error trans " + e); , says error tran [object object]

also i've made alert alert(db) , says : [object object],

res exists in function starts on line:

tx.executesql("select username, password users username = ?", [username], function(tx, res) { 

… 1 of arguments function.

you trying use several lines after function. can used inside it.

related reading: how return response asynchronous call?


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -