Hybrid View

  1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    12
    Vote Rating
    0
    erinhir is on a distinguished road

      0  

    Default Unanswered: Phonegap ==> not all variables are returned from server

    Unanswered: Phonegap ==> not all variables are returned from server


    I wrote a login in sencha touch. Quite simple. A simple form with username and password. Submit a request to the server where I execute a sql to search the corresponding username/password. If a result is found then return success=true and the member_id and member_username.

    It works in Chrome and also using Eclipse/Phonegap.

    Now I expanded the sql so also the password is returned from the sql. In md5 it is stored in the db. So I can store this in the localstorage. For some reason the password I get back from the server is always "undefined". Although in Chrome it works fine. In Eclipse/Phonegap the value is "undefined".

    Here is the code from the JSONP. The code "console.log(response.user.member_pw);" shows "undefined". Allthough in Chrome it is filled in correctly... With the md5 value of the password.

    PHP Code:
    Ext.util.JSONP.request({
                
    url'http://10.0.2.2/mobile/login.php',
                
    paramsoptions.data,
                
    callbackKey"callback",
                
    scopethis
                
    callback: function(response) {
                    
    console.log("checklogin success");
                     if (
    response.success == "true")
                     {
                        
    console.log("Paswoord returned:");
                        
    console.log(response.user.member_pw);
                         var 
    member Ext.ModelMgr.create({
                            
    member_idresponse.user.member_id,
                            
    member_usernameresponse.user.member_username,
                            
    member_passwordresponse.user.member_pw
                        
    }, 'Login');
            
                        
    app.subapps.Login.stores.login.add(member);
                        
    app.subapps.Login.stores.login.sync();
                        
                        
    this.index(options);
                    }
                    else {
                         
    Ext.Msg.alert(''response.errors.reason'');
                         
    console.log("failure");
                    }
                }
            });
        } 
    Here is the code from the login.php

    PHP Code:
    $username $_GET['username'];
    $pw $_GET['password'];

    $callback $_REQUEST['callback'];

    $sql_select "select member_id, member_username, member_password from member where member_username like '".$username."' and member_password like '".md5($pw)."'";
    $sql_result mysql_query($sql_select$db) or die ("Error: ".mysql_error());
    $sql_number_records mysql_num_rows($sql_result);

    if (
    $sql_number_records == 1)
    {
        
    $sql_record         mysql_fetch_array($sql_result);
        
    $idRef_user         $sql_record[0];
        
    $member_username     $sql_record[1];
        
    $member_pw            $sql_record[2];
        
        
            
    $json_return '{"success": "true", "user": { "member_id": "'.$idRef_user.'", "member_username": "'.$member_username.'", "member_pw": "'.$member_pw.'"}}';
            
            if (
    $callback) {
                
    header('Content-Type: text/javascript');
                echo 
    $callback '(' $json_return ');';        
            } else {
                
    header('Content-Type: application/x-json');
                echo 
    $json_return;    
            }
        }
        else
        {
            
    $json_return =  '{"success": "false", "errors": { "reason": "Login failed"}}';
            if (
    $callback) {
                
    header('Content-Type: text/javascript');     
                echo 
    $callback '(' $json_return ');';
            } else {
                
    header('Content-Type: application/x-json');
                echo 
    $json_return;    
            }
        }


  2. #2
    Sencha User
    Join Date
    Apr 2012
    Posts
    12
    Vote Rating
    0
    erinhir is on a distinguished road

      0  

    Default


    I also tried to do a select * or instead of returning the password returning another field from the table. But it keeps being "undefined". With Chrome is works, strange...

    Even if I hard code the password, $member_pw = "mypasswordcomeshereinmd5"; it still is undefined...

    I also hard coded the password in de json object

    '{"success": "true", "user": { "member_id": "'.$idRef_user.'", "member_username": "'.$member_username.'", "member_pw": "mypasswordcomeshereinmd5"}}';

    Still undefined....