【发布时间】:2017-05-25 02:46:19
【问题描述】:
我正在尝试创建一个表单,在单击提交时调用一个函数,该函数将发布到 php 页面(运行查询),然后在页面上显示这些结果。
如果我在加载时在我的控制器中调用所述函数,我会得到我的预期结果(数据以模态形式显示在 html 表中)。但是,如果我在单击提交时调用该函数。我可以记录数据结果,但它没有显示在我的页面上。
$scope.report = {};
var url = "";
// calling our submit function.
$scope.submitForm = function() {
$http.post('url.php').success(function(data) {
// Stored the returned data into scope
$scope.names = data;
console.log(data);
$('#myModal').modal();
});
};
<button type = "button" class="btn btn-success" ng-click="submitForm()" >Submit Request</button>
<div class="modal fade" id="myModal" role="dialog" >
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content" >
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<table class="table table-striped table-bordered">
<tr>
<th>Name</th>
</tr>
<tr ng-repeat="name in names | filter:search_query">
<td><span>{{name.first}}</span></td>
</tr>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
【问题讨论】:
-
首先在 html 视图页面上打印你 {{names}} 并查看结果的结构。发布结果是可能的。
-
我无法将数据结果 {{names}} 打印到页面。我得到的结果就像我试图在模式中显示一样。但是,如果我调用函数 onLoad 而不是 onSubmit,两者都可以工作
标签: javascript php html angularjs