[英]$http.post in AngularJS
我是webdev的新手,我需要使用AngularJS。 使用$ http.post確實有麻煩。
app.controller('searchCtrl', function($scope, $http, $log) {
$scope.search = function() {
$http.post('server.php', { "data" : $scope.keywords})
.success(function(data, status) {
$scope.result = data;
})
};
我使用此控制器(並且工作正常),但是除了$scope.keywords
之外,我想將第二個參數(字符串)傳遞給server.php
。
在服務器端和客戶端,我該怎么做?
調用后期望的路徑是server.php
,主體為JSON對象
您可以簡單地使用JSON.stringify( 任何json abject)。
例如JSON.stringify({ data: $scope.keywords, otherStuff: otherStuff })
我想就是這樣。
所以你會發布:
$http.post('server.php', { "data" : $scope.keywords,"anotherData":anotherData})
並接收數據:
$_POST['data'] and $_POST['anotherData']
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.