doushe2513 2014-03-20 19:27
浏览 40
已采纳

在AngularJS http数据字段中传递的数据

I have this html

<div class="row " style="margin-left:75pt;">
      <div class="dropdown">
        <label class="text-center" style="margin-top:10pt;font-size:14pt;"> Deals on</label>&nbsp;
          <button data-toggle="dropdown" class=" btn dropdown-toggle dropdown-menu-hover-color text-center" style="padding:0px 0px;background-color:white;" href="#"><label style="font-size:14pt; color: #191970;" >{{currentCategory}}</label>&nbsp;<b class="caret"></b></button>
          <ul class="dropdown-menu submenu-hover-color"  style="margin:0;">
                <li><a href="#" id="{{page.category_id}}" ng-click="changeCategory(page.category_id);" ng-repeat="page in dropdownCategoryList" ng-model="category_id">{{page.category_name}}</a></li>
          </ul> 
      </div>
    </div>

And this code in Angularjs controller.

$scope.changeCategory = function(category_id) {
        $window.alert(category_id);
        $http({
            method : 'POST',
            url : '/changeCategory',
            data : category_id,
            headers : { 'Content-Type': 'application/x-www-form-urlencoded' } 
            // set the headers so angular passing info as form data (not request payload)
            }).success(function(data, status, headers, config) {

            }).error(function(data, status, headers, config) {
                $scope.status = status;
                $window.alert("error")
        });
    }

I want to access the category_id parameter of the controller function in AngularJS in Golang at backend,so what should i pass in http's data field.

Thanks in advance

  • 写回答

1条回答 默认 最新

  • doutangshuan6473 2014-03-20 19:32
    关注

    data is a mapping of key/values (requests params essentially)

    data: { 'category_id': category_id }
    

    Then your POST should have a param named "category_id"

    and check this post about handling JSON in go

    Handling JSON Post Request in Go

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?