-1
So I have an application which gets data from a server, the login function is in services.js that's within a factory. Everything is working fine with Ionic serve but running on an actual device nothing works, the response is empty, and now the xhr requests are pending in chrome for some reason, my session variable( as well as our data variable) which is required to access the server is turning up as null on mobile, but again with ionic serve the session variable is being set just fine.


Can't post any code really, but does anyone have any ideas, I would really appreciate it, I've been troubleshooting this for a few days now and nothing has come up.



    "use strict";

    const VERSION  = "3.0" // 2.43
    const BASELINK = "LINK"+VERSION
    const session = localStorage.getItem('session'); // this gets session id
    const MAINLINK = BASELINK + "&job=Search&session="+session;


    angular.module('app.services', [])

    .factory('userData', ($http) => {




    //
    //  This is the main function for user data
    //      used by loginCtrl
    //

    const TOKEN = '';
    const POST_CONFIG   = {
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',

          //  'Content-Type': 'application/x-www-form-urlencoded',
            // application/x-www-form-urlencoded application/json
        }


    }

    var loggedIn = false;

    return {

        login: (credentials) => {
          // Get the username / password entered
        //  $scope.user = document.getElementById('username').value;
        //let username = document.getElementById('username').value;
        //return username;
        console.log(credentials.user)
        console.log("MAINLINK", MAINLINK)
    //=========================---------------------------------------------------------------------------------------------


            // Send a post request to the MobileLogin function
            let body = { "username": credentials.user, "password": credentials.pswd};

            let url = BASELINK+"&job=MobileLogin";
          //  console.log(body, url);
            $http.post(url, body, POST_CONFIG)
                .success(function(data,status,headers,config) {
                    // Successfully contacted the server, now deal with the response
                    let status_code = data.split("|||||")[0];
                    let message = data.split("|||||")[1];
                    console.log(message)
                    console.log("BODY:", POST_CONFIG, body)
                    console.log(body.username)
                    var session='';
                    var username='';
                    eval(data.split('|||||')[2])
                    localStorage.setItem('session',session);
                    console.log('SESSION:',session)
                    localStorage.setItem('username',username);
                    console.log(MAINLINK); // session id
                    if (status_code == 'error') {
                        // There was an error of some sort, most likely entered incorrect information
                        document.getElementById('loginmessage').textContent = message;
                    } else {
                        // Login was successful, now redirect to the Home page
                        document.getElementById('loginmessage').textContent = 'Login Successful!';
                    }
                })
                .error(function(data,status,headers,config) {
                    // There was an error contacting the server
                    document.getElementById('loginmessage').textContent = 'Cannot connect to server.';
                    console.log("DATA: "+data);
                    console.log("STATUS: "+status);
                    console.log("HEADERS: "+headers);
                    console.log("CONFIG: "+config);

                });
    //=========================---------------------------------------------------------------------------------------------
            console.log(credentials);
            loggedIn = true;
        },
        isLoggedIn: () => {
            return loggedIn;



        }
    };
})
.factory('searchData', () => {
  var storedproductCode= "";
  var storedProductLine= "";


     return {
         getValue: function(viewId) {
             return storedProductLine[viewId];
         },
         setValue: function(newValue,viewId) {
             storedProductLine[viewId] = newValue
         },
         deleteOrder: function(viewId) {
             delete storedProductLine[viewId];
         }
     };


})

我已经在上面添加了我的 services.js 代码,你还需要我的控制器代码吗?基本思想是当我尝试在移动设备上访问页面时,会话 id 返回为 null,数据也返回为 null,这不是 ionic serve 的问题,仅在移动设备上运行时,我们只是去修复我们遇到的任何cors问题都不应该是这样

4

2 回答 2

0

你试过离子实验室吗?为什么不发布您的 service.ts 代码?更好地了解问题出在哪里可能会很有用。这可能只是请求标头的问题

于 2018-08-20T22:39:09.857 回答
0

固定的!这个问题与我们的内部网络有关。请关闭

于 2018-08-23T15:12:59.100 回答