Within my HTML code, I have included a button like so:
<button type="submit" id="post-form" class="btn btn-primary" onclick="send()">Send</button>
Accompanying this is the JavaScript function send() :
function send() {
$.ajax({
type: 'POST',
url: "http://app.localhost/feedback",
dataType: "json",
data : {
feedback: $('#feedback').val(),
email: $('#email').val(),
},
success : function(json) {
$('Backdrop').hide();
console.log("requested access complete");
}
});
}
In my Django project views, there is a function associated with the /feedback entry point. However, the process stalls before reaching the success stage. Interestingly, while I can send requests using Postman, executing them through JavaScript proves futile.
The view pertaining to the designated entry point appears as follows:
@csrf_exempt
def feedback(request):
if request.method == 'POST':
body_unicode = request.body.decode('utf-8')
body = json.loads(body_unicode)
fromField = body['email']
subject = 'New FeedBack from {}'.format(fromField)
body = body['feedback']
sendEmail("<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b1d4c9f1d4c99fd2de">[email protected]</a>", subject, body,
replyTo=['<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a0c5d8e0c5d88ec3cf">[email protected]</a>', '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="395c41175c41795e54585055175a5654">[email protected]</a>'])
return redirect('/')