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

198
Views
Post Request works in swagger but not in JavaScript or jQuery

So, I am trying to call a rest API using ajax post. Response contains Status code and Response body which in JSON. When I test this in swagger it works.

enter image description here

When I try this in either JavaScript or JQuery,

const values = {
    clientId: '9d9d865a-96c6-41ff-9842-89101c8ccc7a'
};

$.ajax({
    url: "https://-----.-----------.ca/Asset/EstimatedWaitTime",
    type: "POST",
    data: values,
    contentType: "application/json",
    dataType: "text",
    beforeSend: function(xhr) {
        xhr.setRequestHeader('access-control-allow-headers', 'Origin, X-Requested-With, Content-Type, Accept');
    success: function(response) {},
    error: function(jqXHR, textStatus, errorThrown) {
        console.log(textStatus, errorThrown);
    }
});

I get the following error:

enter image description here

Why is this not working, or what am I doing wrong?

Thank you guys!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It's a Cross-Origin Resource Sharing (CORS) error https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS Best way is your own API with access to external web resource. JS (AJAX request) -> Your API -> External web resource -> Your API -> Your Web page (js response)

about 4 years ago · Juan Pablo Isaza 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!