通过角js ajax向php变量发送div的id值。

时间:2022-09-26 10:57:03

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 ?

我有很多divs,不同的id。我要做的是,当特定的div被单击时,一个js函数将被调用,该div的id值将被发送到php并分配给一个php变量,然后将得到响应。我需要通过角js ajax实现,$http方法。这是我的简单ajax方法,我现在要做什么?

<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){  }
      })
  });

}

1 个解决方案

#1


2  

Just add the data to send:

只需添加要发送的数据:

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

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

并更改标题,将其设置为内容:application/json

#1


2  

Just add the data to send:

只需添加要发送的数据:

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

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

并更改标题,将其设置为内容:application/json