如何从编码JSON的PHP页面获取数据?
请帮帮我,伙计们。我已经思考了几个小时如何解决这个问题,但我仍然不知道如何解决。> 为了访问Js文件中的数据,必须使用ajax。 需要数据时调用ajax 有关更多详细信息,请参阅下面的链接 试试:如何从编码JSON的PHP页面获取数据?,php,angularjs,json,ionic-framework,Php,Angularjs,Json,Ionic Framework,请帮帮我,伙计们。我已经思考了几个小时如何解决这个问题,但我仍然不知道如何解决。> 为了访问Js文件中的数据,必须使用ajax。 需要数据时调用ajax 有关更多详细信息,请参阅下面的链接 试试: $http.get('resources/json/jsonfile.php',{ responseType : 'json' }) 您能将您的Ajax响应记录到console.log中吗$http.get('resources/json/jsonfile.php')。然后(函数(数据){conso
$http.get('resources/json/jsonfile.php',{ responseType : 'json' })
您能将您的Ajax响应记录到console.log中吗<代码>$http.get('resources/json/jsonfile.php')。然后(函数(数据){console.log(数据);})代码>
[{"account_id":"89","username":"2012100014","password":"25d55ad283aa400af464c76d713c07ad"},{"account_id":"90","username":"2012102400","password":"25d55ad283aa400af464c76d713c07ad"},{"account_id":"91","username":"2012101087","password":"25d55ad283aa400af464c76d713c07ad"},{"account_id":"92","username":"2011102090","password":"25d55ad283aa400af464c76d713c07ad"}]
app.service("myService", function($http,$q)
{
var deferred = $q.defer();
$http.get('resources/json/jsonfile.php').then(function(data)
{
deferred.resolve(data);
});
this.getAccounts = function()
{
return deferred.promise;
}
})
.controller("myCtrl",function($scope,myService)
{
var promise = myService.getAccounts();
promise.then(function (data)
{
$scope.allAccounts = data;
var accounts = data;
console.log($scope.allAccounts);
});
})
Object {data: "<?php
↵ //open connection to mysql db
↵ $con…db connection
↵ mysqli_close($connection);
↵?>", status: 200, config: Object, statusText: "OK"}
$http.get('resources/json/jsonfile.php',{ responseType : 'json' })