Deployed django application on nginx problems with fetching

I have a django application that deployed on ubuntu 20. It doesn't have certificate yet. When javascript fetches the backend i guess it just throws error

JSON.parse: unexpected character at line 1 column 1 of the JSON data

That's what i get in Chrome, but in Arc Browser everything works fine and without any errors

Here is my code

JS:

const country_icons = document.querySelectorAll(".country-icon");
country_icons.forEach((icon)=>{
  
  icon.addEventListener("click", (e)=>{
    let id = e.target.id
    fetch(`get-country-info/`,{
      method: "POST",
      body: JSON.stringify({
        id : id
      }),
      headers:{"X-CSRFToken": getCookie('csrftoken') }
    })
    .then(response => response.json())
    .then(data => {
      let text = data[e.target.id]
      let modal_body = document.querySelector("#modal-body");
      modal_body.innerHTML = text

      })
  })

})

views.py


def get_country(request):
    data = json.loads(request.body)
    country_name = data.get("id")
    response_data = {country_name : get_country_info(country_name)}
    return JsonResponse(response_data)

everything works if i run the server with python3 manage.py runserver though

I am using Django 5.0.2, DRF 9.14.0, nginx, gunicorn, ubuntu 20

Back to Top