Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

490
Views
Jquery Ajax not sending headers

I've read countless answers regarding similar questions, but cannot solve my specific issue.

I have a web API that makes a request to RESTful service using a oauth token. This is cross domain.

I know my cors is setup correctly as I can make requests from the app without issue.

My problem is that my headers are not being sent.

$.ajax({
        type: "GET",
        crossDomain: true,
        url: url,
        data: data,
        success: success,
        dataType: 'json',
        cache: false,
        beforeSend: function (xhr) {
            xhr.setRequestHeader("Authorization", "bearer TOKENGOESHERE"),
            xhr.setRequestHeader("RandomHeader", "test")
        }
    });

If I call my API using fiddler and set the header there, the API gets the header as expected. It's only this AJAX call that doesn't seem to work.

I am running this in the latest Chrome browser.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Have you tried to send headers as a parameter?

$.ajax({
    type: 'POST',
    url: url,
    headers: {
        "my-first-header": "first value",
        "my-second-header": "second value"
    }
})
over 4 years ago · Santiago Trujillo Report

0

I had similar symptoms but my specific problem seemed to be I was making an http request to a site that enforced HTTPS, so when the browser got the 301 response pointing to the secure version of the site, it seems like the XHR subsystem follows the redirect but drops the headers in the process.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!