Ich habe Django-Kors-Header verwendet, und konfigurieren Sie es.JSON Parse-Fehler bei POST-Anfrage
Backend: Django 1.11 + django-rest-Framework 3.6.3
settings.py
ALLOWED_HOSTS = ['*']
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
CORS_ORIGIN_ALLOW_ALL = True
Python manage.py runserver 192.168.1.111:8000
Frontend:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$.ajax({url: "http://192.168.1.111:8000/api/user/forgot_password/",
type: "post",
data: {"email": "[email protected]"},
headers:{"Content-Type":"application/json"},
success: function(result){
$("#div1").html(result);
}});
});
});
</script>
</head>
<body>
<div id="div1"></div>
<button>Forget Password</button>
</body>
</html>
Erhalten 400 Antwort für POST-Anfrage und Antwort se Inhalt
{"detail":"JSON parse error - Expecting value: line 1 column 1 (char 0)"}
Aber wenn ich diese API von Postbote seine Arbeit richtig nenne. Wie kann ich dieses Problem lösen?
Bitte einen Blick auf https://stackoverflow.com/help/how-to-answer haben. Versuchen Sie, einige Details in Ihrer Antwort anzugeben, z. warum es nicht funktioniert und was sie versuchen sollten. – majita