通过angular js ajax将div的id值发送到php变量

问题描述:

我的div数量不同,ID不同.我正在尝试做的是,当单击特定的div时,将调用js函数,并且该div的id值将发送到php并分配给php变量,然后将获得响应.我需要通过有角js ajax,$ http方法来完成.这是我简单的ajax方法,我现在要做的是什么?

I have number of divs, with different ids. What i am trying to do it , when that specific div is clicked, a js function will be called and the id value of that div will be sent to php and assigned to a php variable, and then response will be gotten. I need it to be done through angular js ajax, $http method. This is my simple ajax method, what i have to do now ?

<div class="col-sm-4 col-md-4 ppp" ng-repeat="id in d" data-id="32">


function divClick(id){

  var headers = {'Content-Type': 'application/x-www-form- urlencoded'};
  var app = angular.module("myApp",[]);
  app.controller("myCtrl",function($scope,$http){
      $http({
        method:"POST",
        url:"files.php",

        headers:headers
      }).then(function(res){  }
      })
  });

}

只需添加要发送的数据:

Just add the data to send:

$http({
        method:"POST",
        url:"files.php",
        data: {
          "id": id
        },
        headers:headers
      })

并更改标题以设置为内容: application/json

And change your header in order to set as content: application/json