Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7687753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:46:24+00:00 2026-05-31T19:46:24+00:00

I’m working on a consumer for a self-made API and having serious difficulties with

  • 0

I’m working on a consumer for a self-made API and having serious difficulties with setting the Authorization header. I am using JQuery for the Ajax requests, but the ‘beforeSend’ does not work at all (using fiddler to examine the requests)

This is my beforeSend code:

    $.ajax({
     type: "GET",
     url: url+"/Projects",
     contentType: "application/json; charset=utf-8",
     beforeSend: function (req) {
        req.setRequestHeader("Authorization", AuthBuilder(username, password));
     },
     success: function (result) {
        alert("success");
     },
     error: function (xhr, ajaxOptions, thrownError) {
        alert("fail");
     }
 });

Well if that fails what do you do? Go back to the old way for sending ajax requests… well this doesn’t work either…

This is my regular code:

function GET(address, callback, error) {
Request = getXMLHttpObject();
Request.open("GET", url + address, true);

var base64 = Base64.encode(username + ":" + password);
alert(base64);
Request.setRequestHeader("Authorization", "Basic " + base64);

Request.send();
Request.onreadystatechange = function () {
    //alert(Request.readyState+" code "+Request.status);
    if (Request.readyState == 4 && Request.status == 200) {
        callback(jQuery.parseJSON(Request.responseText));
    } else if (Request.readyState == 4 && Request.status >= 400) {
        error(Request.status, Request.statusText);
    }
} 
}

Don’t mind the fact that I’m not asking for json specifically because the service returns json by default.

In additional info:

  • the origin does not matter, the service allows all origins (has been tested and confirmed)
  • the Authorization works when set by headers (tested in other clients)
  • the Authorization headers just aren’t sent
  • AuthBuilder(username, password)) gives the correct format of the Basic Auth header content
  • the getXMLHttpObject() is just some copy paste code and worked before

any thoughts ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:46:26+00:00Added an answer on May 31, 2026 at 7:46 pm

    Well I found out what the problem was. The self-made service sent this back to the client as a global header : “Access-Control-Allow-Headers” with only “Content-Type” in it.

    This way our clients not using an User Agent (browser) ignored these headers and just sent the header anyway. But the browser tried to optimize the request and said “It won’t accept the Authorization header so I’ll just cut it before sending.” this way is the package is smaller and the service won’t allow it anyway (although it did…)

    So just adding “Authorization” to the Access Control Allow Headers part of the service made my Javascript/JQuery/Ajax requests send the request header as normal!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.