使用发布数据点击按钮点击php服务codeigniter

时间:2014-06-07 11:40:42

标签: javascript php jquery angularjs codeigniter

$scope.nextbutton=function()  //on button click this function is called
{
 alert( $scope.datatopass);
 var mm=$scope.datatopass;   //contains data got from ajax response


 //here i need to call service 'preview' that loads a view with my data passed  


}

www.xyz.com/project/controller/preview:

function preview()
{

                $data= json_decode(trim(file_get_contents('php://input')),true);

        $this->load->view('preview_view',$data);
}

我想将按钮点击数据从我的页面传递到控制器,然后我需要使用我的$ data重定向到page-preview_view

1 个答案:

答案 0 :(得分:0)

简单的答案是,在你的angularJS函数中,你可以使用$ http。但是,一个更好的模式是使用服务并完成它,保持与服务器的实际交互(我认为)是你的控制器。

尽管如此,试试这个:

//For angular
app.controller('someController', function($http, $scope){

  $scope.nextButton = function(){
     $http.post('/url/to/post/to', $scope.data).success(function(result){

          //Result from server
          console.log(result);
      });
    };

});