The submission of an Angular form through the post method is not working

I am experiencing an issue with this angular code that is preventing the URL from being submitted via post. My goal is to send form details through SMS, requesting a call back 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 could be missing or what errors might I be making?

Your assistance in resolving this issue would be greatly appreciated!

Thank you, Sj

Answer №1

Implement this code snippet in your controller:

$scope.formAdata={};

If you are using JSON parameters, ensure that formAdata is binding correctly.

Additionally, verify that you are using POST method but passing data as a query string. It is recommended to bind and send the data as a JSON object or switch to the GET method.

Double-check if the value of 'messenger' is being assigned since no data type 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) {

        });
    };
});

By following these steps, your code should work properly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I am facing an issue with body-parser not properly processing my request in express.js

Utilizing the Controller in my project. Snippet from app.js: var express = require('express'); var app = express(); const routes = require('./Routes/route'); const bodyParser = require('body-parser'); app.use('/', ...

Organize and categorize items

I need help sorting an object displayed below. My goal is to calculate the sum of all rating properties for each object, and then sort the objects based on the highest total rating. For instance, if the total rating for Intro 1 is 7 and for Intro 2 is 3, ...

A code snippet designed to ensure uniform height for all floating div elements

Hello, I am facing an issue with resizing 20 left-floated divs of varying heights on my website. Previously, when my website was designed using pixels, a script worked perfectly for resizing them. However, after switching to a percentage-based design (% d ...

Whenever I try to access my Node.js API from Heroku's live server, I encounter a CORS policy error

Whenever I try to access my Node.js API from the Angular app (running on a local setup) and host the API on Heroku's live server, I encounter the following error: CORS policy: No 'Access-Control-Allow-Origin'. Interestingly, when I host the ...

Guide on how to display an HTML file in Vue JS that is received from the server

I'm brand new to Vue JS and currently grappling with how to display an HTML page sent by the server. For example, let's say I have a Node router named "health" that sends an HTML file like this: res.sendFile('test.html', { root: path.d ...

How can I utilize a filter or pipe to populate product categories onto screens within Ionic 2?

I am considering creating an Ionic 2 app with 6 pages, but I'm unsure whether to utilize a Pipe or a Filter for the individual category pages and how to implement the necessary code. Each category page should be able to display products from the "app ...

Integrating a module function with an AngularJS service

After reviewing the contents of these two links 1 and enter link description here, I've gained insight into the importance of maintaining clean and modular code. The approach outlined in the aforementioned links advocates for separating functions int ...

Working with dynamic checkbox values in VueJS 2

In my project using VueJS 2 and Vuetify, I am creating a subscription form. The form is dynamic and fetches all the preferences related to a subscription from the server. In the example below, the preferences shown are specifically for a digital magazine s ...

Unable to open modals in Bootstrap using jQuery script: modal not popping up

My attempt to create functionality for two buttons and two modals - reserve a campsite (id="reserveButton" should open id="reserveModal") and Log in (id="loginButton" should open id="loginModal") is not working. I ha ...

How can AJAX be used to execute a PHP script that deletes a record from a database table?

Yesterday, I asked for help on how to save user-generated blog posts and I successfully tackled the database aspect of it. Now, my next goal is to be able to delete a blog post upon clicking a button with an onclick event. After researching extensively onl ...

What is the best way to take control of DOM alterations?

In the project I'm currently working on, the client has a modal box with its display property set to none. Upon clicking the CTA button, it triggers the application of the fadein and fadeout classes. This results in a change from display:none to displ ...

Check out the selected values in Ionic 3

I am trying to retrieve all the checked values from a checkbox list in an Ionic3 app when clicked. Below is the code snippet: <ion-content padding> <ion-list> <ion-item *ngFor="let item of items; let i= index"> <ion-label>{{i ...

Embed a Style-sheet into an Iframe (Facebook Like Box)

I'm facing the challenge of customizing a Facebook like box with predefined image sizes and borders that don't align with our design. I want to override some styles to make it more suitable for our website. The Likebox is currently embedded via ...

Can someone please explain this async-await code block to me in simple terms? I don't understand why user.password_hash is

I am completely new to node.js, express, and the concept of async/await functions, promises, callbacks, etc. The specific issue I need help with is located towards the end of the code snippet I've provided. While the code does seem to be functioning ...

Within the ASP.NET Framework 4, it is necessary to enable the Listbox control to trigger an event when a user double

Currently, I am developing a project in ASP.NET 4. I have encountered a situation where the regular ListBox in version 4.5 includes an attribute named OnMouseDoubleClick. However, since I am using ASP.Net 4, I am looking for the best approach to replicat ...

Instructions on converting XML data obtained from an AJAX call into a downloadable file

I've been struggling with converting an AJAX response containing XML text into a downloadable file. I've tried various methods but haven't had success. In the past, I was able to work with a similar scenario involving a pdf, where the conte ...

What is the best way to halt Keyframe Animation once users have logged in?

To enhance user engagement, I incorporated keyframe animation into my login icon on the website. The main objective is to capture the attention of visitors who are not registered users. However, once a user logs in, I intend for the keyframe animation to c ...

When the program is executed, immediately use .trigger('click')

There is a spelling game that features a grid filled with hidden words. The objective of the game is to spell out these words by clicking on the letters of the alphabet, aided by hints such as images and sounds. Players are given the word they need to spe ...

Identify when a click occurs outside of a text input

Whenever text is typed into the textarea, the window changes color. The goal is to have the color revert back when clicking outside the textarea. <textarea class="chat-input" id="textarea" rows="2" cols="50" ...

Encountering Error: When Running the Command "npm run dev" it's Showing "missing script: dev" Message

I attempted to set up the SVELT GitHub repository locally by following these steps: https://github.com/fusioncharts/svelte-fusioncharts When I tried to launch it using the "npm run dev" command, I encountered this error: npm ERR! missing script: dev To ...