2017-05-31 32 views
0

我在寻找一种方法来从输入到一个PHP变量插入范围的数据,这是怎么了我的代码看:插入从范围数据PHP变量与Ajax请求

HTML:

<div class="form-group" ng-app="Filter" ng-controller="InsertFilter"> 
<form> 
    <label for="limit">Limit:</label> 
    <input type="text" class="form-control" id="limit" name="limit" ng-model="limit"> 
    <label for="page">Page:</label> 
    <input type="text" class="form-control" id="page" name="page" ng-model="page"> 
    <label for="from">From:</label> 
    <input type="date" class="form-control" id="from" name="from" ng-model="from"> 
    <label for="to">To:</label> 
    <input type="date" class="form-control" id="to" name="to" ng-model="to"> 
    <button type="submit" class="btn btn-default" style="margin-top: 15px;">Show Report</button> 
</form> 

Ajax请求在角:

var FilterApp = angular.module('Filter', []); 
     FilterApp.controller('InsertFilter', function($scope, $http) { 
     $http.post("/api/data-dashboard.php").then(function(response){ 
     $scope.limit = /* ??? */; 
    }); 
}); 

数据dashboard.php:

if (empty($_POST["from"])) { 
$from = date('Y-m-d'); 

} else { 
$from = $_POST["from"]; 
} 

if (empty($_POST["to"])){ 
$week = time() + (7 * 24 * 60 * 60); 
$to = date('Y-m-d', $week); 
} else { 
$to = $_POST["to"]; 
} 

if (empty($_POST["page"])) { 
$page = 1; 
} else { 
$page = $_POST["page"]; 
} 

if (empty($_POST["limit"])) { 
$limit = 10; 
} else { 
$page = $_POST["page"]; 
} 

感谢您的所有好评。
*我应该将输入转换为json格式吗?

回答

0

收集所有的细节形成角HTTP请求使用

$postdata = file_get_contents("php://input"); 
$request = json_decode($postdata); 
$from = request->from; 

而且通过参数设置为$ http.post

$http.post("/api/data-dashboard.php",{from:$scope.from}).then(function(response){});