Using AngularJS for Basic Authentication with $http

Recently, I encountered an issue while trying to set up a login service for my app. Here is the code snippet using $http:

$http({
        method:"get",
        url: ## BLAH BLAH BLAH,
        headers: {
            'Authorization': 'Basic ' + $base64.encode(loginData.username + ':' + loginData.password)
        }
    }).then(function success(response){
        ## BLAH BLAH BLAH
    }, function error(response){
        ## BLAH BLAH BLAH
    });

Upon running this $http request, I received an error on the console:

XMLHttpRequest cannot load ## BLAH BLAH BLAH. 
Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response.

I am confused about what could be causing this issue. Any insights or suggestions would be greatly appreciated. Thank you, Lucas.

Answer №1

Take a look at the same origin policy, and take note that www.balabala/api is not equal to balabala/api

I suspect you are making calls from balabala to www.balabala/api or from www.balabala to balaba/api, make sure to set the url to /api.

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

Release a stationary element upon scrolling down the page

I have a calculator feature on my website which was coded in php. At the end of this calculator, there is a section that displays the results. While the results div works properly on desktop, I am looking to implement a fix for mobile devices. Specificall ...

Can $scope be considered as a dependency in this scenario?

My perspective is this: When you include a controller parameter called $scope, AngularJS recognizes the $scope parameter and generates the $scope object, injecting it into our controller where the $scope parameter was placed. Is injecting that object con ...

Using jQuery to apply custom classes on a row in RShiny is a great way to

Building upon this initial inquiry, the following code showcases two separate containers, each containing a series of elements provided by the `sortable` R package. Within each container are specific functions called `add_rank_list`, serving different purp ...

Ways to verify if a minimum of three letters in each variable correspond

let nameOne = 'chris|'; let nameTwo = 'christiana'; To use JavaScript, what is the best way to determine if three or more letters match between both variables? ...

Issue with AJAX form submission selecting an incorrect row among dynamically generated rows of data

Currently, I am fetching data from a database and displaying it in a table. One column includes the ID of each row, which I then pass to a modal using the following code snippet: <a href=".user_id<?php echo $row['id']; ?>" ...

A single button that performs multiple actions with just one click

Summary: Seeking assistance in implementing a button that triggers three different actions upon being clicked thrice. Detailed description: On one page of my website, there is an introduction with text and images. I currently have a button that switches t ...

Issue encountered while trying to send JSON data via the $http function

I'm encountering an issue with the JSON.stringify method in my code. Here's what I have: var JsonObject = {}; JsonObject['key'] = '987'; JsonObject['val'] = '1234'; JsonObject['val2'] = '123 ...

Display a variety of images when hovering over different elements

I have a logo in various colors that I want to cycle through on hover. The default image is black, then changes to red on the first hover, yellow on the second hover, and blue on the third hover. This cycle continues back to black and repeats. Any suggesti ...

Error: Security Exception raised when making nested ajax requests

Here's a problem I'm facing. I've been using an ajax call in JavaScript/jQuery to extract Gmail contacts like so: function getUserInfo() { var xml_parse = ""; $.ajax({ url: SCOPE + '?max-results=9999&access_token=' + a ...

Enhancing Websites with Vimeo Pictures and JavaScript

Having some issues with my thumbnail system. It's supposed to fetch an image from Vimeo and display it in a div. I attempted to create a loop for a nicer look, but unfortunately, it's not working as expected. Can anyone provide assistance? ...

Implement a JSON.parse fallback mechanism for an undefined array to prevent any potential exceptions

When parsing my array, everything works fine if it is defined: JSON.parse(myArray); However, I encounter an exception if myArray is undefined. What would be the best solution for this? Is there a more efficient alternative to this: JSON.parse(myArray | ...

The background-size:cover property fails to function properly on iPhone models 4 and 5

I have taken on the task of educating my younger sister about programming, and we collaborated on creating this project together. Nicki Minaj Website However, we encountered an issue where the background image does not fully cover the screen when using b ...

Unraveling the mystery: accessing the same variable name within a function in JavaScript

What is the best way to reference the same variable name inside a function in JavaScript? var example = "Hello"; console.log("outside function: " + example) function modifyVariable() { var example = "World!"; console.log("inside function: " + ex ...

Tips for recalling the active URL you just clicked on - is it in JavaScript or PHP?

I currently have an HTML select list menu in place. When a user selects an option, they are redirected to the corresponding page. For example, if they select "Faizabad" from the menu, they will be redirected to http://example.com/towns/Faizabad. The menu b ...

Are the Node.JS environment variables missing?

In my Node.JS application, I have set up some crucial environmental variables in the .env file, such as AUTH0_CLIENT_ID and AUTH0_CLIENT_SECRET. To enable Auth0 support on the client side, I included the following code: var jwt = require('express-jw ...

Is the session information lost during the redirect?

Trying to save the user's role using $_SESSION['role'] == $row['role']; When the username 'admin' logs in, it verifies if the role Admin exists in the SQL database and, if it does, redirects the user to admin.php. Ho ...

calling the setState function multiple times

I keep calling the setState function multiple times in a row by pressing the down button, but I noticed that React JS stops updating the state after around 40-50 updates. Each click increases the sold value by one. Is this normal behavior for React JS, or ...

Unable to locate the tag using .find() function following the use of .attr() method

I am currently utilizing jQuery in conjunction with node-horseman to interact with a specific page. My approach involves referencing the page's data-id attribute, which I then pass to my application to search for the li element containing this attribu ...

Pair of Javascript Functions Using Async with Parameters

This question builds upon a previous inquiry raised on Stack Overflow: When considering approach number 3 (referred to as the "counter" method), how can we ensure that the function handleCompletion can access necessary data from startOtherAsync to perform ...

Switch out "FOR" in order to sum up every value within an array

Utilizing Javascript, I have an array defined as follows: counts: [ { id: 1, value: 0 }, { id: 2, value: 10 }, { id: 3, value: 5 }, { id: 4, value: 3 } ] I aim to calculate a variable named total that holds the sum of all valu ...