Angular http请求缺少帖子值

时间:2015-04-16 13:05:32

标签: javascript php angularjs http-post httprequest

我正在制作http request我需要用它发送一些值。

Http请求

$http({
           url: 'user_resources/delete.php',
           method: 'POST',
           data: { parent_state: parent_state, course_id: course_id, filename: material_to_delete.material.file_name }
    });

它运行php file,但$_POST值不存在。我还尝试在headers: {'Content-Type': 'application/x-www-form-urlencoded'}中加入http request,但没有任何运气。有人可以帮我弄清楚我做错了什么吗?

提前谢谢!

更新

控制器

app.controller('CourseEditController', ['$http', '$scope','$sessionStorage','$state','$log','Session','api','$filter', function ($http, $scope, $sessionStorage, $state, $log, Session, api, $filter) {
    var course_id = $state.params.course_id;
    var parent_state = $state.$current.parent.name;

    $scope.deleteMaterial = function (idx) {
        var material_to_delete = $scope.course.course_has_materials[idx];
        $http({
            headers: {'Content-Type': 'application/x-www-form-urlencoded'},
            url: 'user_resources/delete.php',
            method: 'POST',
            data: { parent_state: parent_state, course_id: course_id, filename: material_to_delete.material.file_name }
        });
    };
}]);

HTML

<table class="table table-striped b-t b-light" ng-controller="CourseEditController">
   ...
   <tbody>
      <tr ng-repeat="material in course.course_has_materials">
          <td class="l-h-2-5x">{{ material.material.file_name }}</td>
          <td class="l-h-2-5x">{{ material.material.file_type }}</td>
          <td class="l-h-2-5x text-right pointer">
             <i class="fa fa-times" ng-click="deleteMaterial($index)"></i></td>
      </tr>
   </tbody>
</table>

1 个答案:

答案 0 :(得分:0)

查看@epascarello发布的帖子帮我解决了我的问题。

$http({
      headers: {'Content-Type': 'application/x-www-form-urlencoded'},
      url: 'user_resources/delete.php',
      method: 'POST',
      data: $.param({parent_state: parent_state, course_id: course_id, filename: material_to_delete.material.file_name})
 });

如果将来有人出现同样的问题。