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

387
Views
JQuery $.ajax error: No 'Access-Control-Allow-Origin' header is present on the requested resource

I have an JQuery ajax request which throws me an error:

Access to XMLHttpRequest at 'http://localhost:8080/api/v1/2523/export-pdf' from origin 'http://xxxxx.localhost' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

But I am pretty sure I have Access-Control-Allow-Origin: * set properly. This is the request object, where as you can see Access-Control-Allow-Origin header.

Accept: */*
Access-Control-Allow-Origin: *
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: http://xxxxxx.localhost/
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="102", "Google Chrome";v="102"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
User-Agent: Mozilla/5.0 ...

This is the js code:

var data = {
    lang: lang,
    client: company,
    campaign_name: campaign_name,
    crm_token: {$api_token},
};

var url = {$api_url} + campaign_id + '/export-pdf';

$.ajax(url, {
    headers: {
        'Access-Control-Allow-Origin': '*'
    },
    type: 'POST',
    data: data,
    dataType: 'application/pdf',
    crossDomain: true,
    
    success: function(data) {
        console.log('result data');
        console.log(data);
        var downloadUrl = window.URL.createObjectURL(new Blob([data]));
        var link = document.createElement('a');
        link.href = downloadUrl;
        link.setAttribute('download', fileName);
        document.body.appendChild(link);
        link.click();
        link.remove();

    error: function (data) {
                    form.find('#pdfExportFormErrors').removeClass('d-none').html('PDF download error.');
});

What am I doing wrong? Please help. Thanks.

about 4 years ago · Santiago Gelvez
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!