2016-04-01 12 views
0

私は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に2つ目のパラメータ(文字列)を渡したいと思います。

サーバーとクライアントの両方で、どうすればよいですか?

+3

$ http.post( 'server.phpという'、{ "データ":$ scope.keywords、 "anotherData" :anotherData}) –

+0

しかし、server.phpファイルでanotherDataを使用するにはどうすればよいですか? –

+1

サーバ側では、$ _SERVERまたは$ _POST変数にいくつかのパラメータがありますので、そこでチェックしてください。彼らはおそらくjson、json_decode *なのでしょう。 – Astaroth

答えて

0

ですから、投稿になります。

$http.post('server.php', { "data" : $scope.keywords,"anotherData":anotherData}) 

をし、データを受け取る:

$_POST['data'] and $_POST['anotherData'] 
0

ポストコールは期待しているパスserver.phpと体JSON.stringifyを使用しているあなたが何単にすることができますJSONオブジェクト

絶望的な任意のJSON)。

JSON.stringify({ data: $scope.keywords, otherStuff: otherStuff })

それは私が推測します。