以下代码出了什么问题?我可以直接通过任何浏览器获取JSON结果,它只是不想显示在下拉列表中
我只是想在离子框架中从mysql数据库填充到组合框。
更新的脚本
在下拉列表中仍然为空。任何人吗?
addlist.html
<ion-header-bar align-title="center" class="bar-stable">
<h1 class="title">Add Lists</h1>
</ion-header-bar>
<ion-view>
<div class="list has-header padding">
<label class="item item-input item-select">
<div class="input-label">
Category
</div>
<div ng-controller="AddListCategoryCtrl">
<select ng-model="category" ng-options="x.category for x in data">
<option ng-repeat="x in data" value="{{x.id}}">{{x.category}}</option>
</select>
</div>
</label>
</div>
</ion-view>
controllers.js
angular.module('ionicApp.controllers', [])
.controller('AddListCategoryCtrl', function($scope, $http) {
var xhr = $http({
method: 'post',
url: 'http://www.mywebsite.com/api/listCat.php'
});
xhr.success(function(data){
$scope.data = data.data;
});
});
listCat.php
<?php
include 'db.php';
getById();
function getById() {
$sql = "SELECT id,category FROM tbl_category ORDER BY tbl_category.id";
try {
$db = getDB();
$stmt = $db->prepare($sql);
$stmt->execute();
$category = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
echo '{"category": ' . json_encode($category) . '}';
} catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
}
?>