dongmi1872 2015-07-17 08:12
浏览 43
已采纳

Angular无法将函数的计算数据作为JSON发送

In a form, I am trying to send data as json to a php file, which is calculated correctly from a function in controller. But, if I try to send this calculated data as json, header shows as blank object. Can someone tell me why?

FORM:

<form id="form1" post="">
    <p ng-model="result">{{add()}}</p>
    <button type="submit" class="btn btn-default" ng-click="submitting()" >Submit</button>          
</form>

CONTROLLER:

$scope.submitting = function(){
    var request = $http({ method: "post", url: "php/store.php", 
    data: {"Answer": $scope.result} });
    request.success(function (data) { 
        //alert("Successfully data entered! "); 
    });
}


$scope.add = function(){ 
    var a = 10; var b = 20; var c = a + b;
    return c;
}
  • 写回答

1条回答 默认 最新

  • doupi7619 2015-07-17 08:19
    关注

    problem was inside your controller it should be like this

    FORM:

    <form id="form1" post="">
        <p >{{add()}}</p>
        <button type="submit" class="btn btn-default" ng-click="submitting()" >Submit</button>          
    </form>
    

    CONTROLLER:

    $scope.submitting = function(){
        var request = $http({ method: "post", url: "php/store.php", 
        data: {"Answer": $scope.add()} });
        request.success(function (data) { 
            //alert("Successfully data entered! "); 
        });
    }
    
    
    $scope.add = function(){ 
        var a = 10; var b = 20; var c = a + b;
        return c;
    }
    

    Fiddle:https://jsfiddle.net/xrx5Lxwk/1/

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

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序