简体   繁体   中英

Angular form not submitting via post

Please check why this angular code does not submit url via post. I am trying to send my form details through sms, to post a request via mobile.

<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>

What must be missing, or what am doing wrong?

Please help!

Thanks, Sj

add this to your controller

$scope.formAdata={};

your using json parameters, so your formAdata doesn't gets binded properly.

Also check you are using POST but passing the data like a query string , so need to bindand send as a json object or use GET method.

One more thing double check if the value of messenger is getting assigned or not since there is no datatype is mentioned

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) {

        });
    };
});

This will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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