Ionic和angular-向服务器发送http请求并接收JSON数据,这适用于Ionic serve,但不适用于运行Android的Ionic Cordova

Ionic和angular-向服务器发送http请求并接收JSON数据,这适用于Ionic serve,但不适用于运行Android的Ionic Cordova,json,angular,ionic-framework,xmlhttprequest,serve,Json,Angular,Ionic Framework,Xmlhttprequest,Serve,我已经在上面添加了services.js代码,您还需要我的控制器代码吗?基本思想是当我尝试访问手机上的页面时,会话id返回为null,数据也返回为null,这不是ionic serve的问题,只有在手机上运行时,我们才去修复我们遇到的任何cors问题,所以不应该是它你尝试过ionic lab吗?你为什么不发布你的服务代码?更好地了解问题所在可能是有用的。这可能只是请求头的问题已修复!这个问题与我们的内部网络有关。请关闭你是说services.js?爱奥尼亚的服务——实验室比常规的爱奥尼亚服务做了

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

你尝试过ionic lab吗?你为什么不发布你的服务代码?更好地了解问题所在可能是有用的。这可能只是请求头的问题

已修复!这个问题与我们的内部网络有关。请关闭

你是说services.js?爱奥尼亚的服务——实验室比常规的爱奥尼亚服务做了什么?我们以前遇到过cors问题,这可能仍然会导致问题吗?我们已经添加了一些东西来支持服务器上的cors,但至少在chrome上没有cors插件的情况下,它似乎仍然不起作用。我们的标题“内容类型”:“应用程序/x-www-form-urlencoded”,“跨域”:“true”,“访问控制允许方法”:“获取、发布、删除、放置、选项”,“访问控制允许标题”:“x-request-With,内容类型,授权,来源,接受”,“Access Control Allow Origin':“*”,您好,我已经添加了我的服务代码。js如果您需要更像我的控制器的代码,请告诉我。我认为您需要更多地使用请求的标题
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];
         }
     };


})