Issue with AngularJS: The console.log statement is not showing any output

I recently created a controller for a login page. Below is the controller code I wrote:

var authApp = angular.module('loginApp', [])

authApp.controller('LoginCtrl', ['$scope', '$location', 'loginFactory', function($scope, $location, loginFactory){
    $scope.authenticate = function() {
        loginFactory.login($scope.username, $scope.password)
        .then(function(response) {
            console.log(response.$statusText);
        }, function errorCallBack(response) {
            console.log(response.$statusText);
        });
    }

}]);

Here is my service:

authApp.factory("loginFactory", function ($http) {
    return{
        login: function(username, password) {
            var data = "username="+username+"&password="+password+"&submit=Login";
            return $http({
                method: 'POST',
                url: 'http://localhost:8080/login',
                data: data,
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                }
            });  
        }

During debugging, I noticed that the authentication process appears to be successful as it enters the then function. However, nothing is being displayed in the console. Furthermore, I received a warning showing 'undefined' for the line

console.log(response.$statusText);
even though it's not showing any errors in red. Any ideas why it's not printing anything?

Answer №1

Make sure to utilize response.statusText instead of response.$statusText. AngularJS $http requests documentation specifies statusText as a key property of the response object - https://docs.angularjs.org/api/ng/service/$http

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

Focus on selecting each label within a table using JavaScript

In my current setup, I am attempting to customize radio buttons and checkboxes. Array.from(document.querySelectorAll("tr")).forEach((tr,index)=>{ var mark=document.createElement("span"); Array.from(tr.querySelectorAll("input")).forEach((inp,index ...

ordering the date and time in a reverse sequence using javascript

I am working with dynamically generated date and time data and I am looking to sort them in descending order using JavaScript. Here is an example of the data format I am dealing with: var array= ["25-Jul-2017 12:46:39 pm","25-Jul-2017 12:52:23 pm","25-Ju ...

Retrieve the maximum numerical value from an object

My goal is to obtain the highest value from the scores object. I have a global object called "implementations": [ { "id": 5, "project": 'name project', "scores": [ { "id": 7, "user_id": 30, "implement ...

Adjust the color of the navbar only after a user scrolls, with a slight delay rather than

My code changes the navbar colors when I scroll (200ms). However, I would like the changes to occur when I am slightly above the next section, not immediately. In other words, what adjustments should I make to change the color in the next section and not ...

Angular 6 - The state of the expression was altered after it was verified, different types of constructions

During the build process in debug mode with ng build, I am encountering errors in some components. However, when I switch to production mode using ng build --prod, these errors disappear. I am curious as to why this discrepancy is occurring. Error: Expre ...

The issue of Django and Ajax not automatically updating data

A Save button has been developed. When the user clicks the "Save" button, a record is saved to their collection, changing the button text to "Saved". The user can then click on "Saved" to unsave the record. The record can be successfully saved, and the aj ...

Leverage the power of PHP files within your JavaScript code

I have a PHP file with some calculations that I want to integrate into another JavaScript file. How can I pass variables from JavaScript to perform calculations inside the PHP file? Here is my JavaScript code: $("#upload").on("click", function(){ var ...

Is it possible to create dynamic meta tags in Angular that will appear in a Twitter-style card preview?

My project involves building a dynamic website using a Java app that serves up a REST-ish JSON API along with an Angular9 front end. A key requirement is the ability to share specific URLs from the app on platforms like Twitter and Slack, which support Twi ...

Pagination activates on the second tap

Check out my example on jsFiddle: https://jsfiddle.net/0se06am5/ class Pagination extends React.Component { constructor(props) { super(props); this.state = { current: 1 }; this.items = ['a', 'b', 'c&ap ...

Navigating a single page application with the convenience of the back button using AJAX

I have developed a website that is designed to function without keeping any browser history, aside from the main page. This was primarily done for security reasons to ensure that the server and browser state always remain in sync. Is there a method by whi ...

Ruby On Rails: Dealing with Partial Page Loading

As a newcomer to Ruby on Rails, I'm struggling to find answers to an issue I'm facing in my web app. After a few clicks in my development environment, some pages stop loading data abruptly without any error messages in the console or Firebug. The ...

What is the best way to transfer the $rootscope, which contains numerous parameters, to a state in AngularJS's UI-Router?

Hey there, I'm a new developer facing an issue with passing a root-scope parameter to my state using UI-Router. Here's the original href that I'd like to convert to ui-sref: href="/mycarts/{{cats.id}}?{{$root.filterParams}} This is the st ...

Should a React application perform a complete refresh when a file is reloaded?

Recently, I delved into the world of React and learned about one of its key benefits: updating only the necessary DOM elements. However, as I began building an app from scratch, I encountered a situation where every time I saved the .js file, it resulted ...

Error received - CORS request denied on Firefox browser (Ubuntu)

I encountered a CORS error (CORS request rejected: https://localhost:3000/users) while attempting to register a new user. This issue arose from content in the book Building APIs with node.js, Chapter 12. I am currently using Firefox on Ubuntu and have tr ...

Carousel Pagination: Using Titles Instead of Numbers

I am currently working on implementing a carousel pagination using the Caroufredsel plugin. I am looking to create unique custom Titles for each slide in the pagination, rather than using default numbers. My goal is to have completely different Titles fo ...

Creating circular patterns with looping on a canvas

My goal is to draw circles in a loop, but when I execute my code, I am encountering an unexpected result: The intention is to simply draw 3 circles in random positions. Here is my current code: for (var i = 0; i < iloscU; i++) { ctx.strokeStyle = ...

Determine the mean values to showcase at the center of a D3 donut graph

Check out this plunkr where I'm utilizing angularjs and d3.js. In the plunkr, I've created several donut charts. I'm interested in learning how to display the average data in the center of the arc instead of the percentage. Additionally, I& ...

Understanding the moment when the DOM is fully rendered within a controller

I'm currently facing an issue with AngularJS. In my controller, I have a $watch setup like this: function MyController() { $watch('myModel', function() { $rootScope.$emit('do-oper'); }); } The value of 'myMod ...

Obtain the output of a single controller in a different controller within the Express framework

Seeking to invoke a function from one controller in another Controller1.js 2) Controller2.js Code within Controller1.js file: var Controller2= require('../controllers/Controller2.js'); exports.getlist = function (req, res, next) { Control ...

Passing an empty object in axios with Vue.js

When sending an object from this.productDetails in an axios.post() request, I noticed that the object appears empty when inspected in the browser's network tab. Here's the Axios call: async addProduct(){ console.log('pro ...