Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

121
Visualizações
How we can call python POST request API from JQuery Ajax It showing CORS policy error

I have python API which is POST request,

http://192.168.2.25:8059/calculation

In Postman it return response like (Expected output should be same as like below)

[
    {
        "Indexs_q1": [ 13,14,15,],
        "Points_q1": [ 69,72,75,]
    }
]

In my case I am calling this API which is already in json format like ,

api_Object = {
    "avg":[30,33,36],
    "data":[10,20,30],
    "Avg_xbar":66,
    "ucl":116.776,
    "lcl":15.224
}

$.ajax({
    url: "http://192.168.2.25:8059/calculation",
    type: "POST",
    data: api_Object,
    //data: JSON.stringify(api_Object),
    dataType: "json",
    success: function (response)
    {
        var resp = JSON.parse(response);
        alert(resp.status);
    },
    error: function (xhr, status) {
           alert("error");
    }
});

NOTE : It showing error - Access to XMLHttpRequest at 'http://192.168.2.25:8059/calculation' from origin 'http://localhost:65047' 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.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

After facing lots of issue finally I got an solution,

    $.ajax({
        url: "http://192.168.2.25:8059/calculation",
        type: 'POST',
        dataType: 'json',
        cors: true,
        contentType: 'application/json;charset=UTF-8',
        secure: true,
        data: api_Object,
        headers: {
            'Access-Control-Allow-Origin': '*',
        },
        success: function (data, status, xhr) {
            console.log('success');
        },
        error: function (jqXhr, textStatus, errorMessage) {
            console.log('error');
        }

    })
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda