简体   繁体   English

在Anjularjs中发布隐藏字段值并获取PHP

[英]Post hidden field value in Anjularjs and get in PHP

Hello i am try to post hidden value but its not post or i not getting in php. 您好,我尝试发布隐藏值,但未发布或我没有进入php。 Here is my both code Html with Angular and PHP. 这是我用Angular和PHP编写的Html代码。 So i check result in ajax_function.php page but i got only text box value not getting hidden field value. 所以我在ajax_function.php页面中检查结果,但是我只有文本框值而不是隐藏字段值。

<input type="text" name="Addon_Name" id="Addon_Name" ng-model="formData.Addon_Name" />
<input type="text" class="form-control" name="Addon_Price" id="Addon_Price" ng-model="formData.Addon_Price" />

<input type="hidden" name="someData" ng-value="data" />

<button type="submit" value="123" id="btn_Addon">Submit</button>    

<?php print_r($_POST); ?>

<script>

    var formApp = angular.module('formApp', []);

    function formController($scope, $http) {
    $scope.Hidden_Addon = "1";
        $scope.formData = {};

        $scope.processForm = function() {

            $http({
                method  : 'POST',
                url     : 'ajax_function.php',
                data    : $.param($scope.formData), 
                headers : { 'Content-Type': 'application/x-www-form-urlencoded' }
            })
                .success(function(data) {
                    console.log(data);
                    if (!data.success) {
                        alert(data);
                        // if not successful, bind errors to error variables
                      //  $scope.errorName = data.errors.name;
                      //  $scope.errorSuperhero = data.errors.superheroAlias;
                    } else {
                    alert(data);
                        // if successful, bind success message to message
                       // $scope.message = data.message;
                         //           $scope.errorName = '';
                       // $scope.errorSuperhero = '';
                    }
                });
        };
    }
</script>                   

yes hidden value not post value in anjularjs but we can bind some value and its value using in php function. 是的,隐藏值不是在anjularjs中发布值,但是我们可以在php函数中使用绑定一些值及其值。

like that. 像那样。 $http({ method : 'POST', url : 'ajax_function.php', data : $.param($scope.formData)+"&Hidden_Addon=Yes", headers : { 'Content-Type': 'application/x-www-form-urlencoded' } }) $ http({方法:“ POST”,URL:“ ajax_function.php”,数据:$。param($ scope.formData)+“&Hidden_​​Addon = Yes”,标头:{'Content-Type':'application / x- www-form-urlencoded'}))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM