1

I am trying to build a web app using django. I want to show a form where the user answers a question. The form displays correctly, and I am able to submit correctly without ajax. I want the form data to post without refreshing the page. I am new to web development, and I am having a hard time finding answers to my specific questions. When I click submit the form doesn't submit through django (which is intended), but my development server doesn't receive a post request. Also I keep getting an error "Uncaught RangeError: Maximum call stack size exceeded at xb (jquery-3.1.1.min.js:formatted:3481)"

html:

<head>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>

<body>
HOSTED VIDEO
  {{form1.ch}}
  {% csrf_token %}


<script>
$(document).on("submit","#form1",function(e){
     e.preventDefault();
 const csrftoken = document.querySelector('[name=csrfmiddlewaretoken]').value;
$.ajax({
  headers: {'X-CSRFToken': csrftoken},
  type:"POST",
  url: "/hlg/",
  data: {'form':form1},
  success: alert('yay')
 })
 });
</script>
</body>
Amessihel
  • 4,794
  • 1
  • 12
  • 36

0 Answers0