Я использую следующий вид для моей функции поста Ajax, и вызов неоднократно прерывается. Я могу понять, что здесь не так. Кто-нибудь может указать на это
def interview(request):
if request.is_ajax():
if request.method == 'POST':
name = request.POST.get('name', False)
email = request.POST.get('email', False)
skype_id = request.POST.get('skype_id', False)
phone = request.POST.get('phone', False)
time_slot_1 = request.POST.get('time_slot_1', False)
time_slot_2 = request.POST.get('time_slot_2', False)
time_slot_3 = request.POST.get('time_slot_3', False)
recipients = ['abc@gamil.com']
subject = 'Interview Appointment'
message = "The following person has registered for interview \n Name: %s \n Email: %s \n Skype Id: %s \n Phone: %s \n Slot-1: %s \n Slot-2: %s \n Slot-3: %s" % ( name, email, skype_id, phone, time_slot_1, time_slot_2, time_slot_3)
from django.core.mail import send_mail
send_mail(subject, message, sender, recipients)
return_message = "Sent mail"
return HttpResponse(return_message,mimetype='application/javascript')
Мой JavaScript также довольно прост, но я не знаю, почему я получаю сообщение об ошибке
var email_val = $("#emailp").val();
var skype = $("#skypeId").val();
var phone = $("#phone_no1").val();
var t1 = $("#time_slot1").val();
var t2 = $("#time_slot2").val();
var t3 = $("#time_slot3").val();
$.ajax({
type: "POST",
url: "/interviews/interview_form/",
data: {
'name': name_val,
'email': email_val,
'skype_id': skype,
'phone': phone,
'time_slot_1': t1,
'time_slot_2': t2,
'time_slot_3': t3,
},
success: function(){
alert("call successful");
$('#complete').html("Form has been Submitted");
},
error: function(){
alert("call failed");
$('#error').html("Form could not be Submitted! Please try again");
},
});
Любые идеи приветствуются.