📜  在 django 中处理 ajax 请求 - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:26.534000             🧑  作者: Mango

代码示例1
// 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!")