【问题标题】:Don't get JSON-Data from PHP-Server / Ionic Application - AngularJS不要从 PHP-Server/Ionic 应用程序获取 JSON 数据 - AngularJS
【发布时间】:2016-06-08 09:46:33
【问题描述】:

我搜索了每个主题,但没有找到答案。 我只是想从这个地址获取数据到我的离子应用程序中, 但总是得到这个:

{"$$state":{"status":0}}

我在一家工厂工作:

.factory('Markers', function($http) {

 var markers = [];

    return {
    getMarkers: function(){

    return $http.get("http://geofence.obcc-dd.webseiten.cc/marian/markers.php").then(function(response){
      markers = response;
      return markers;
        });

        } }})

还有这个控制器代码:

.controller('MapCtrl', function($scope, $state, $cordovaGeolocation, Markers) {
 var options = {timeout: 10000, enableHighAccuracy: true};

    $cordovaGeolocation.getCurrentPosition(options).then(function(position){

       console.log("Data:");  
       console.log(Markers.getMarkers()); //here the 0-state appears...

   var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

我无法处理也无法使用所需的数据。 请帮帮我-我吓坏了... ;(

【问题讨论】:

    标签: javascript php angularjs ionic-framework


    【解决方案1】:

    这将帮助你确定

    像这样调用你的服务方法

    Markers.getMarkers(function(response){
    
     console.log(response); 
    
    }); 
    

    然后像这样定义你的服务方法

    getMarkers: function(callback){
    
     $http.get("http://geofence.obcc-dd.webseiten.cc/marian/markers.php").then(function(response){
    callback(response)
            });
    } }})
    

    还有其他方法,但最好的方法已经给出,请让我知道代码的输出,因为它没有经过测试。 如果需要明确的解决方案,请发布代码 sn-p 或创建 plunker

    【讨论】:

      猜你喜欢
      • 2015-01-28
      • 2020-02-19
      • 2019-11-08
      • 2016-05-25
      • 1970-01-01
      • 2015-11-01
      • 1970-01-01
      • 2019-01-17
      • 2015-04-04
      相关资源
      最近更新 更多