The $http request is aborted

I'm having trouble with sending a post request to the server from my login form as it keeps getting canceled.

Below is the controller code:

angular.module('app.signin', [])
.controller('SigninController', ['$http', function($http) 
{
    this.email      = null;
    this.password   = null;

    this.signIn = function()
    {
        var res = $http.post( 'http://api.svcassist.dev/index.php/auth/login', {email: this.email, password: this.password });

        res.success(function(data, status, headers, config) 
        {
                alert(data);
        });
    };
}]);

And this is how the HTML looks like:

<div class="container" style="max-width:300px" ng-controller="SigninController as signin">
    <form class="form-signin">
        <h2 class="form-signin-heading">Sign In</h2>
        <label for="inputEmail" class="sr-only">Email address</label>
        <input type="email" id="inputEmail" name="email" class="form-control" placeholder="Email address" required autofocus ng-model="signin.email">
        <label for="inputPassword" class="sr-only">Password</label>
        <input type="password" id="inputPassword" name="password" class="form-control" placeholder="Password" required ng-model="signin.password">
        <br/>
        <button class="btn btn-lg btn-primary btn-block" ng-click="signin.signIn()">Sign In</button>
    </form>
</div> 

However, when trying to make the request, Chrome indicates that it gets canceled. Here are the response headers:

Request URL:http://api.svcassist.dev/index.php/auth/login
Request Headers
Provisional headers are shown
Accept:application/json, text/plain, */*
Content-Type:application/json;charset=UTF-8
Origin:http://localhost:8000
Referer:http://localhost:8000/app/index.html
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36
X-DevTools-Emulate-Network-Conditions-Client-Id:6C7F2AA6-481A-32ED-0CFC-8F4B9F5927B8
Request Payloadview parsed
{"email":"email","password":"pass"}

Answer №1

If you're looking for a solution, I recommend utilizing ng-submit:

html

<div class="container" style="max-width:300px" ng-controller="SigninController as signin">
    <form ng-submit="signin.signIn(signin.email, signin.email)" class="form-signin">
        <h2 class="form-signin-heading">Sign In</h2>
        <label for="inputEmail" class="sr-only">Email address</label>
        <input type="email" id="inputEmail" name="email" class="form-control" placeholder="Email address" required autofocus ng-model="signin.email">
        <label for="inputPassword" class="sr-only">Password</label>
        <input type="password" id="inputPassword" name="password" class="form-control" placeholder="Password" required ng-model="signin.password">
        <br/>
        <button class="btn btn-lg btn-primary btn-block" type="submit">Sign In</button>
    </form>
</div> 

js

this.signIn = function(email, password)
{
    var res = $http.post( 'http://api.svcassist.dev/index.php/auth/login', {email: email, password: password });

    res.success(function(data, status, headers, config) 
    {
            alert(data);
    });
};

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

Adjusting a polyline in Google Maps

I've successfully used Google Maps V3 API to create a polyline with 2 points. However, I now need to shorten the polyline. Issue: My goal is to make the polyline extend from the start point to the midpoint between the start and end points. How can I ...

The MVC Controller is unable to retrieve decimal values from an Ajax POST request

I am facing an issue with the POST function in my code. While string and integer values are reaching the Controller without any problem, double values are not being received on the server side. Interestingly, when I test on my local machine, everything wor ...

Using Vue.js to pass a variable from a parent component to a child component

Parent component: ShowComment Child component: EditComment I'm attempting to pass the value stored in this.CommentRecID to the child component. In the template of ShowComment, I have included: <EditComment CommentRecID="this.CommentRecID" v-if= ...

execute a function that invokes a class method

Within my component, I have implemented a method that includes a jQuery event binding functionality. jqueryNextDataEditableShow() { $('#symbolTable .editable').on('hidden', function (e, reason) { if (reason === 'save&apo ...

What is the purpose of having the same function for onPress in React Native components?

As a beginner in learning react-native, I like to search random projects on GitHub and analyze what seems weird or hard to understand. Today, I came across some code from an unknown individual that looked like this: {isTrue && ( <Touch ...

The jQuery mouseout event is activated whenever my tooltip is hovered over

Recently, I encountered an issue with a menu that adds a https://i.sstatic.net/A0J2U.png Within the menu, there is jQuery code that functions to add a class on hover and remove it on mouse-out. The code snippet looks something like this... $(document).r ...

Why is this chip-list not functioning properly in my Angular 14 and Angular material application?

I'm currently developing a form using Angular 14. My goal is to incorporate a field with Angular Material chips. Within the component's Typescript file, I have the following code: constructor(private fb: FormBuilder,) { } public visible: boole ...

When extracting information from a table within a Vue.js and Vuetify.js function

When trying to display a table, only one row is being printed. How can I resolve this issue? I have attempted various solutions (Vanilla JS worked). This project is for educational purposes and I am relatively new to JS and Vue.js. <template> < ...

Having trouble with ng-click in AngularJS while using dataTables

I created a custom dataTables directive for AngularJS, and it's mostly working well. However, I'm facing an issue when trying to add a button to each row that will remove the respective row when clicked using ng-click. My suspicion is that the p ...

What is the most efficient way to establish a connection to "host:port" without relying on a web browser, utilizing only Node.js/JavaScript?

To establish a connection with a server (created using node js), we simply open the browser and include some code in a file like this: <script src="http://127.0.0.1:8080/socket.io/socket.io.js"></script> <script type="text/javascript">/* ...

What could be causing the multifiles uploader to fail in uploading files?

I have been attempting to create a multiple files uploader with sorter connected to a database on my website. However, whenever I try to upload some files, the uploader sends me several notices. Notice: Undefined index: media in /var/www/mediasorter/mediau ...

Expand and collapse button for viewing more content

I need help figuring out how to display a list of 10 items on my website. I want to show only three items initially, with a "View More" button that, when clicked, will reveal the remaining items. The button should then change to "View Less" so users can ea ...

Generate a mongoose output by iterating through a loop within Koa.js

My current setup involves using Koa.js in combination with Mongoose.js. Within my MongoDB database, there exists a collection called css which has the following schema: _id css_name css_value In my code, I have an array that contains a large number of el ...

javascript categorize data by key and display in a tabular format

I have a Client ID and gender information available. Shown below is a JSON response along with a JavaScript function to display the data in a table format. The JSON response structure is as follows: studies = [{ "id": { "Value&qu ...

I aim to utilize vanilla JavaScript in order to remove the parent element of the button being clicked when the user interacts with it

My latest project involves a meme generator that allows users to input text and images, which are then combined to create a unique 'meme'. Each meme is assigned a unique ID and features buttons for deleting the meme upon hovering. To achieve this ...

The useEffect hook is executed only once and will not fetch data again upon refreshing the page

There's this component in my project that fetches data from a website and attempts to extract its keys. The issue I'm facing is that it functions correctly the first time, but upon refreshing the page or saving the project in VSCode (which trig ...

Paragraph featuring keywords highlighted by categoryIn this text, we will be analyzing different categories

I am looking to implement a visual feature similar to the image below using react js. Can anyone provide guidance on how to accomplish this? I have a collection of words categorized as Organization, Person, and Location. My goal is to assign different colo ...

What could be causing a Typescript-defined class property to unexpectedly appear as undefined?

My component has a property called options, which I have defined in the class. However, when I run the code in the browser, it's showing up as undefined. Despite thoroughly checking the code logic, I can't seem to pinpoint any issues. This could ...

Error: JSDOM - The document variable has not been declared

After creating a basic webpage that displays a single message, I decided to experiment with JSDOM and encountered an error. Despite researching online examples and Stack Overflow questions, I have struggled to resolve even the most straightforward scenario ...

Issue encountered while attempting to install Parcel, with errors being triggered in the parcelwatcher and in the process of

1 npm ERR! path C:\Users\USER\OneDrive\Documents\My sites\Music Website\node_modules@parcel\watcher npm ERR! command failed npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node-gyp rebuild npm ER ...