My javascript code raise an error in my production server (nginx+gunicorn) when all is ok in dev.
here is my js
many thanks for your help
<script>
const findLoc = () => {
const success = (position) => {
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
var data = {'latitude': latitude,
'longitude': longitude };
data.csrfmiddlewaretoken = $('input[name=csrfmiddlewaretoken]').val();
console.log('Location is on');
console.log(data);
document.getElementById("LocationLat").innerHTML = latitude;
document.getElementById("LocationLon").innerHTML = longitude;
**$.post("gps/", data,function(response) {**
// La réponse est maintenant disponible dans la variable 'response'
console.log('Réponse reçue:', response);
document.getElementById("postdata").innerHTML = response;
$('.spinner-border').hide();
// Faites quelque chose avec les données, par exemple mettre à jour le contenu de la page
}).fail(function(xhr, status, error) {
// En cas d'échec de la requête, affichez l'erreur
console.log('Erreur lors de la requête:', status, error);
});
}
const error = () => {
console.log('Location gathering Not allowed')
$('.spinner-border').hide();
document.getElementById("postdata").innerHTML ="Activate position in your browser !"
}
navigator.geolocation.getCurrentPosition(success,error);
}
</script>
in bold the error is raised by this instruction
here the console in the browser :
enter image description here
urls.py
urlpatterns = [
path('admin/', admin.site.urls),
path('gps/',views.home_view),
views.py
def home_view(request):
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
ip = x_forwarded_for.split(',')[0]
else:
ip = request.META.get('REMOTE_ADDR')
if request.method == 'POST':
Latitude = float(request.POST.get('latitude'))
Longitude = float(request.POST.get('longitude'))
context = aviationweatherapi.getStationInfo(None,Latitude,Longitude)
print ("Get airports list around current GPS location")
#print (context)
templateview='partial-results.html'
else:
#The request is GET
list ='LFHC,LFHN,LFHS,LFJD,LFKY'
context = aviationweatherapi.getStationInfo(list, None, None)
context.update({'IP':ip})
print ("Get all airports")
templateview='acceuil.html'
context.update({'IP':ip})
return render(request,templateview,context)
i hope resolve this error because without response data from my view anything is displayed
New contributor
Heavy PC is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.