Ionic http get请求(带Ionic)返回html数据

时间:2016-02-22 08:10:56

标签: angularjs ionic-framework

我正在使用 Ionic 并提出http这样的请求:

$http.get('//GLOBAL.IP/?username=' + username + '&content_type=json')
            .then(function (result) {
                $scope.days = [];

                alert(JSON.stringify(result));

                for (first in result.data.weeks) break;

                var currentWeek = result.data.weeks[first];
                var time = currentWeek.overall.as_time;

                $scope.week = currentWeek;
                for (day in currentWeek.days.sort().reverse()) {
                    if (day < 2) {
                        continue;
                    }
                    var currentDay = currentWeek.days[day];
                    $scope.days.push(currentDay);

                    if (currentDay.present) {
                        console.log(parseInt(currentDay.work_time_balance) + parseInt(currentWeek.overall.seconds));
                    }

                }
            }, function (result) {

                alert(JSON.stringify(result));

                $ionicPopup.alert({
                    title: 'Error',
                    template: 'Connection failed, try again later!'
                });
            })
            .finally(function () {
                // Stop the ion-refresher from spinning
                $scope.$broadcast('scroll.refreshComplete');
            });

当我使用命令ionic serve在浏览器中打开应用程序时,一切似乎都正常,我已经修复了CORS和其他内容。 但是当在移动应用程序中,我得到这个(抱歉不提供明文)

enter image description here

更新

        $http.get('//GLOBAL.IP/?username=' + username + '&content_type=json')
            .then(function (result) {
                alert('Good');
            }, function (result) {
                alert('Bad');
            })

此代码返回GOOD,但result.data仍为脚本标记。

2 个答案:

答案 0 :(得分:1)

当你在工作模式下测试这个应用程序时localhost是什么,它是在同一台机器上运行的本地服务器,对吧。

在您指向的移动设备中安装或运行应用程序时?您知道吗,如果代码没问题,那么用机器的IP替换localhost应解决此问题。

答案 1 :(得分:0)

离子式http请求响应中script的许多addRow个标签是由于uri开头的//,协议在浏览器中成功选择,但在编译的应用中没有。< / p>

相关问题