繁体   English   中英

如何将json数组从服务器上的php文件传递到我的Ionic应用程序?

[英]how can i pass json array from php file on a server to my ionic app?

我正在开发一个Ionic应用程序,我必须将数据从后端(服务器上的php文件)传递到Ionic应用程序,并从Ionic应用程序传递到后端。 我尝试了这个:

.controller('AppCtrl',function($scope,$ionicPlatform,$location,$http,$ionicHisto
ry, $ionicModal, $timeout,$cordovaSQLite) {


$ionicPlatform.ready(function(){


$http.get('http://http://localhost/ShuttleFIX/json.php')
    .success(function(data,status,headers,config){
          var user = data;
          for(i = 0; i<user.length; i++){
            var cell = user[i].cell;
            var nome = user[i].nome;
            var cognome = user[i].cognome;
            var mail = user[i].mail;
            var codF = user[i].codF;
            var pwd = user[i].pwd;
          }
    }
});

我知道我必须使用http请求,但我不知道如何,有人可以帮助我吗? 谢谢

确定的第一件事是如何从服务器php返回和接收数据。 定义方法GETPOST ,如果使用GET,则必须将URL与要发送的参数组合在一起。 如果是Post,则通常以JSON格式提供,并传递参数data

似乎束没有尝试很多,但或多或​​少是这样的:

GET:

.controller('AppCtrl', function($scope, $http){
    var url = "http://myhost/name="+$scope.name;
    $http({ method: 'GET', url: url, dataType: "json", contentType: "application/x-www-form-urlencoded" })
    .success(function(data) {
        console.log(data);
    })
    .error(function(response) {
        console.log("error");
    })
    .finally(function() {

    });
})

开机自检:

    var data = {
         name : $scope.name
    }
    $http({ method: 'POST', url: url, dataType: "json", data: data})
    .success(function(data) {

    })
    .error(function(response) {
          console.log("error");
    })
    .finally(function() {

    });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM