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

120
Views
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 answers
Answer question

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 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!