javascript - Angular 表单未通过邮寄提交

标签 javascript angularjs asynchronous http-post

请检查为什么此 Angular 代码不通过帖子提交网址。我正在尝试通过短信发送我的表单详细信息,以通过手机发布请求。

<div id="page7-container1" ng-app="amApp">
      <h4 id="page7-heading1" style="color:#000000;">App</h4>
      <div id="page7-markdown3" class="show-list-numbers-and-dots">
      </div>
      <div id="page7-markdown6" class="show-list-numbers-and-dots">
      </div>
      <div id="page7-markdown5" class="show-list-numbers-and-dots">
      </div>
      <div id="page7-markdown4" class="show-list-numbers-and-dots">
      </div>
      <h3 id="page7-heading4" style="color:#337AE2;font-weight:600;">Request a call back</h3>
      <form id="page7-form2" class="list" ng-controller="formCtrl" ng-submit="submitForm()">
        <label class="item item-input item-floating-label" id="page7-input0">
          <input type="text" name="formAdata.rname" required placeholder="Enter Your Name">
        </label>
        <label class="item item-input item-floating-label" id="page7-input1">
          <input type="number" name="formAdata.rmobile" required placeholder="Enter Mobile Number">
        </label>
        <label class="item item-input item-floating-label" id="page7-input2">
          <input type="text" name="formAdata.rlocation" required placeholder="Enter Your location/district/state?">
        </label>
        <input id="page7-button12" type="submit" ngClick="Submit" class="button button-positive  button-block" value="Request call back!">
      </form>
        <script language="javascript">
            var messager = '';
            var app = angular.module('amApp', []);
            app.controller('formCtrl', function ($scope, $http) {
                $scope.submitForm = function() {
                    messager = "http://amritamultimedia.co.in/sms/sendsms.php?uid=9947009540&pwd=A3228B&msg=I am "+$scope.formAdata.rName+" from "+$scope.formAdata.rLocation+". My mobile number is: "+$scope.formAdata.rMobile+", I would like to get more info about Courses. Requested call back from your Mobile App, Please call me to my mobile.";
                    $http({
                        url: messager,
                        method: "POST",
                        headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                        data: $.param($scope.formAdata)
                    }).success(function(data, status, headers, config) {
                        document.getElementById("page7-form2").innerHTML = "We will get back to you within 3-4 hours. Thanks for checking our app.";
                    }).error(function(data, status, headers, config) {

                    });
                };
            });
        </script>
    </div>

一定缺少什么,或者做错了什么?

请帮忙!

谢谢, Sj

最佳答案

将其添加到您的 Controller

$scope.formAdata={};

您使用 json 参数,因此您的 formAdata 无法正确绑定(bind)。

还要检查您是否使用POST,但像查询字符串一样传递数据,因此需要绑定(bind)并作为json对象发送或使用GET> 方法。

由于没有提到数据类型,所以还要仔细检查信使的值是否被分配

var app = angular.module('amApp', []);
app.controller('formCtrl', function ($scope, $http) {
    $scope.formAdata={};
    var messager = "";
    $scope.submitForm = function() {
        messager = "http://amritamultimedia.co.in/sms/sendsms.php;
        var userData={
        "uid":mobilenumber,
        "pwd":password,
        "phone":$scope.formAdata.phone,
        "msg": $scope.formAdata.message
        }
        $http({
            url: messager,
            method: "POST",
            headers: {'Content-Type': 'application/x-www-form-urlencoded'},
            data: userData,
        }).success(function(data, status, headers, config) {
            document.getElementById("page7-form2").innerHTML = "We will get back to you within 3-4 hours. Thanks for checking our app.";
        }).error(function(data, status, headers, config) {

        });
    };
});

这会起作用。

关于javascript - Angular 表单未通过邮寄提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40575117/

相关文章:

javascript - Leaflet openstreetmap 加载,但不出现

javascript - 通过标签名称更改类名称

angularjs - Protractor 测试在 Chrome/Firefox 中完成,但在 phantomjs 中失败

javascript - Ng-click 不起作用

ajax - AngularJS 结合 Web 服务响应

c# - 监视超时的同步方法

javascript - 如何在 javascript 中获取 dd/mm/yyyy 格式的年份

python - Python Flask 上的同步 api 任务

node.js - 是否可以使用许多函数(超过 10 个)来处理 Node 的异步特性(尤其是添加到 MySql 数据库时)

javascript - 如何使用 node.js 服务器处理大量负载?