Javascript 使用AngularJS Http Post以html格式将数据发布到服务器

Javascript 使用AngularJS Http Post以html格式将数据发布到服务器,javascript,html,angularjs,Javascript,Html,Angularjs,我想问一下关于发帖的问题,实际上我有一个下面的表格,在这个表格中,我使用了ng submit和ng click的功能,但它不起作用,有人能帮我吗 <form method="post" class="sky-form" name="form"> <div class="row"> <div class="col col-12"><img src="public/images/icon_namapasien.png" alt=""/

我想问一下关于发帖的问题,实际上我有一个下面的表格,在这个表格中,我使用了ng submit和ng click的功能,但它不起作用,有人能帮我吗

<form method="post" class="sky-form" name="form">
    <div class="row">
        <div class="col col-12"><img src="public/images/icon_namapasien.png" alt=""/> Nama Pasien</div>
    </div>
    <div class="row">
        <div class="col col-10">
            <div ng-repeat="profile in profil">
                <label class="input disabled">
                    <input type="text" ng-model="profile.name">
                </label>
            </div>
        </div>
        <div class="col col-2">
            <a class="btnstatus">&nbsp;</a>
        </div>
    </div><!-- /row -->

    <div class="row">
        <div class="col col-12"><img src="public/images/icon_tgl.png" alt=""/> Tanggal Lahir</div>
    </div>
    <div class="row">
        <div class="col col-3">
            <label class="select">
                <div ng-repeat="profile in profil">
                    <select name="gender" ng-model="profile.birth_date">
                        <option ng-repeat="n in range(01,31)" value="{{n}}">{{n}}</option>
                    </select>
                    <i></i>
                </div>
            </label>
        </div>
        <div class="col col-4">
            <label class="select">
                <div ng-repeat="profile in profil">
                    <select name="gender" ng-model="profile.birth_month">
                        <option value="01">Januari</option>
                        <option value="02">Februari</option>
                        <option value="03">Maret</option>
                        <option value="04">April</option>
                        <option value="05">Mei</option>
                        <option value="06">Juni</option>
                        <option value="07">Juli</option>
                        <option value="08">Agustus</option>
                        <option value="09">September</option>
                        <option value="10">Oktober</option>
                        <option value="11">November</option>
                        <option value="12">Desember</option>
                    </select>
                    <i></i>
                </div>
            </label>
        </div>
        <div class="col col-3">
            <label class="select">
                <div ng-repeat="profile in profil">
                    <select name="gender" ng-model="profile.birth_year">
                        <option ng-repeat="n in range(1910,2016)" value="{{n}}">{{n}}</option>
                    </select>
                    <i></i>
                </div>
            </label>
        </div>
        <div class="col col-2">
            <a class="btnstatus">&nbsp;</a>
        </div>
    </div><!-- /row -->

    <div class="row">
        <div class="col col-12"><img src="public/images/icon_gender.png" alt=""/> Jenis Kelamin</div>
    </div>
    <div class="row">
        <div class="col col-10">
            <div class="select">
                <label class="select">
                  <div ng-repeat="profile in profil">
                        <select name="gender" ng-model="profile.gender">
                                <option value="1">Pria</option>
                                <option value="0">Wanita</option>
                        </select>
                            <i></i>
                    </div>
                </label>
            </div>
        </div>
        <div class="col col-2">
            <a class="btnstatus">&nbsp;</a>
        </div>
    </div><!-- /row -->

    <div class="row">
        <div class="col col-12"><img src="public/images/icon_alamat.png" alt=""/> Alamat</div>
    </div>
    <div class="row">
        <div class="col col-10">
            <div ng-repeat="profile in profil">
                <label class="input disabled">
                    <input type="text" ng-model="profile.address"/>
                    <input type="hidden" name="name" value="0" ng-model="kodekota">
                </label>
            </div>
        </div>
        <div class="col col-2">
            <a class="btnstatus">&nbsp;</a>
        </div>
    </div><!-- /row -->

    <div class="row">
        <div class="col col-12"><img src="public/images/icon_telp.png" alt=""/> Nomor Telepon / Hp</div>
    </div>
    <div class="row">
        <div class="col col-10">
            <div ng-repeat="profile in profil">
                <label class="input disabled">
                    <input type="text" value="" ng-model="profile.phone"/>
                </label>
            </div>
        </div>
        <div class="col col-2">
            <a class="btnstatus">&nbsp;</a>
        </div>
    </div><!-- /row -->
    <p>&nbsp;</p>
    <button class="btn-yellow" type="submit" name="submit" ng-click="postProfil()">Simpan Perubahan</button>
</form>
你们觉得怎么样?谢谢

编辑:


也许我会改变我的问题,你知道使用AngularJS从APIRL中以前的数据更新数据的代码吗?因此,我的问题是getProfil和postProfil的键和值相同(但我认为有些键不同)。

只需使用
ng model$scope.profile

  $scope.postProfil = function(){
    $http.post('/postUrl', $scope.profile).success(function(data){
        $scope.getProfil();
    }).error(function(data){
        console.log(data);
    })
  }
你应该为你的问题做点什么

$http.post接受(url、数据、选项?) 另一方面,$http直接接受(选项)。你可以像这样使用它

$http({
    url: 'api/create/something',
    data: yourData,
    method: 'POST'
}).then(....)
此代码与上述代码的工作原理相同


关于不准确的数据绑定。这可能是大小写敏感问题,或者是RESTAPI配置带来的序列化问题。有时,PASCALCASE变量不会按原样绑定到camelCased变量。需要进行一些配置。

制作一个Rest API来实现这一点。使用ng资源来实现这一点,您介意给我举个例子吗@AhmadSharifI使用了这个,当getProfil()绑定出现时,里面没有值…顺便说一句,谢谢你的回答。。。你有什么想法吗?检查服务器端发生了什么我只是在前端,但是当我使用postman时,值可以保存在服务器内部,这是我的问题吗?谢谢你的回答,不知为什么我认为后端可能有问题,但我认为没有。。。正如我在问题中所说,我已经提醒了数据,但它返回“Undefined”,我不知道我的问题出在哪里,即使它是区分大小写的,我也会识别它,直到现在我电脑中的最新代码在上面。我想这是因为profile.name在ng repeat指令中。(ng repeat=“profile中的profile”)。在这种情况下,变量“profile”将无法通过控制器访问,因为它是在“profile”数组上迭代时的迭代器值。如果我使用value而不是ng model,结果将为null,因为“value”和ng model冲突(我不知道确切的术语),结果是字段未显示。那么您有什么想法吗?在输入中使用ng值可以让您预先设置该输入的数据,该数据还绑定到附加到它的ng模型。但是,输入值的键入和更改不会反映到ng值,它只反映到指定的ng模型。所以,为了从输入中捕获数据,必须始终使用ng模型作为最终值。但正如我所说,问题在于表单位于迭代器(ng repeat)中,只能通过在代码中迭代名为“profil”的数组来访问。
  $scope.postProfil = function(){
    $http.post('/postUrl', $scope.profile).success(function(data){
        $scope.getProfil();
    }).error(function(data){
        console.log(data);
    })
  }
$http.post('api/create/something', yourData)
$http({
    url: 'api/create/something',
    data: yourData,
    method: 'POST'
}).then(....)