Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

197
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda