通过angular js ajax将div的id值发送到php变量 [英] Sending the id value of a div through angular js ajax to php variable

查看:51
本文介绍了通过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

这篇关于通过angular js ajax将div的id值发送到php变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆