Error OPTIONS net::ERR_CONNECTION_REFUSED

I am developing a web application using “jQuery”(front-end) and “Python”(back-end). While making a PUT request to update details in the database, this is the error I get in the console:

OPTIONS “REST API URL” net::ERR_CONNECTION_REFUSED

My jQuery code is:

$.ajax({ 
    type: "PUT",
    url: "REST API URL",
    headers: {"Content-Type": "application/json", "Authorization": AuthToken},
    data: "details to be updated in database",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(data,status) {
      //do something with data
    },
    error: function(data,status) {
      //show error data and status
    }
)};

I read about how HTTP Requests other than GET and POST are first pre-flighted as OPTIONS request and only when it is a genuine request, it gets processed as a PUT/DELETE/PATCH request.
I saw solutions where it said that it might be a CORS issue, but CORS is enabled from the back-end to allow GET/POST/PUT/PATCH/DELETE requests. Further, I am successfully able to make GET and POST requests but no PUT requests are going through.
I am using “Chrome Dev Tools” and researched about how to fix this error for Chrome by clearing cache and cookies, flushing DNS and re-installing Chrome but none of the solutions have worked so far.
I am a making the front end UI and am not sure whether this is a client-side error or a server-side error?
Any help would be appreciated.

Leave a Comment