Answers for "handling ajax requests in django"

1

handling ajax requests in django

// 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!")
Posted by: Guest on September-22-2021

Code answers related to "TypeScript"

Browse Popular Code Answers by Language