Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

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!")
 
PREVIOUS NEXT
Tagged: #handling #ajax #requests #django
ADD COMMENT
Topic
Name
4+3 =