📅  最后修改于: 2022-03-11 14:48:26.534000             🧑  作者: Mango
// Posting data
$.ajax({
type: 'POST',
url: '/home/add_to_newsletters/',
// Data object along with the csrfmiddlewaretoken
data: {
'email': email.value,
'csrfmiddlewaretoken': document.getElementsByName('csrfmiddlewaretoken')[0].value,
},
success: function(resp){
// Do something on success
}
});
class AddToNewsletters(View):
def post(self, request):
posted_email = request.POST['email']
print(posted_email)
return HttpResponse("Ajax with Django Success!")