Why does my JavaScript code receive a No Access-Control-Allow-Origin header is present on the requested resource error while Postman does not

0 votes

I'm attempting to provide authorisation using JavaScript by connecting to the RESTful API integrated into Flask. 

However, when I make the request, I receive the following error:

XMLHttpRequest cannot load http://myApiUrl/login. 
No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'null' is therefore not allowed access.

I'm attempting to provide authorization using JavaScript by connecting to the RESTful API integrated into Flask. 

However, when I make the request, I receive the following error:

$.ajax({
      type: 'POST',
      dataType: 'text',
      url: api,
      username: 'user',
      password: 'pass',
      crossDomain: true,
      xhrFields: {
        withCredentials: true,
      },
    })
      .done(function (data) {
        console.log('done');
      })
      .fail(function (xhr, textStatus, errorThrown) {
        alert(xhr.responseText);
        alert(textStatus);
      });
Sep 20, 2022 in Java by Nicholas
• 7,760 points
507 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Java

0 votes
1 answer

no 'access-control-allow-origin' header is present on the requested resource

The java <class-name> command syntax is one ...READ MORE

answered Feb 8, 2022 in Java by Soham
• 9,710 points
773 views
0 votes
0 answers
0 votes
2 answers
0 votes
2 answers

When I am running eclispe on my computer it is throwing error. How to resolve it?

If you have downloaded the 64 bit ...READ MORE

answered Dec 10, 2018 in Java by Sushmita
• 6,920 points
1,039 views
0 votes
1 answer

CORS in AWS API Gateway + AWS Lambda

You could try downloading the AWS APIG ...READ MORE

answered Oct 9, 2018 in AWS by Priyaj
• 58,020 points
4,082 views
0 votes
1 answer

What is jQuery?

Hey, jQuery is a fast and concise JavaScript ...READ MORE

answered Feb 14, 2020 in JQuery by kartik
• 37,520 points
1,316 views
0 votes
1 answer

Uncaught TypeError: Cannot read property 'msie' of undefined - jQuery tools

Hello, Use the following script tag in your ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,840 points
15,711 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP