我对angularJs完全不熟悉。我想使用php获取提交到mysql数据库的表单数据,然后在ng-view上显示它。
以下是我的代码:
viewevent.js
eventsApp.factory('viewEvent',function($http,$log)
{ return {
getEvent: function (successcb){
$http({method:'GET',
url:"http://localhost/apidocs/display.php"})
.success(function (data,headers,status,config){
successcb(data);
}).error(function(data,status,headers,config){
$log.warn(data,status,header,config);
});
}
};
});
viewCtrl.js
eventsApp.controller('viewCtrl',function viewCtrl($scope,viewEvent)
{
viewEvent.getEvent(function(event){
$scope.Events= event;
});
});
和 ViewEvent.html
<div class="table-responsive">
<table class="table table-bordered table-striped" id="box-table-b" >
<tr>
<th> Name</th>
<th> Address</th>
</tr>
</table>
<ul>
<li ng-repeat = "Evnt in Events track by $index">{{Evnt.name}} <br/>
{{Evnt.address}}
</li>
</ul>
</div>
这是我正在使用的php文件:
<?php
$con=mysqli_connect("localhost","root","","eventsapp") ;
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
echo 'Connected successfully';
//select
$query = "SELECT * FROM event";
$result = mysqli_query($con,$query);
if (!mysqli_query($con,"SELECT * FROM event")) { die('Error: ' . mysqli_error($con));
}
$arr = array();
$arr2 = array();
//now we turn the results into an array and loop through them.
while ($row = mysqli_fetch_assoc($result)) {
$name = $row['name'];
$address = $row['address'];
$arr = array(
"name"=>$name,
"address"=>$address );
array_push($arr2, $arr);
}
echo json_encode($arr2);
?>
我的控制台没有错误。我只在屏幕上获取子弹作为输出。 请指导!..提前谢谢您的建议..