I'm trying to submit a django form via ajax, but I get this error message: Btw my urlpatterns should be fine, they work properly when I simply render the site.
jquery-3.5.1.js:10099 POST http://127.0.0.1:8000/%7B%%20url%20%22landing-home%22%20%%7D 404 (Not Found)
Here's my url file:
from django.urls import path
from Landing import views
urlpatterns = [
path('', views.home, name='landing-home'),
]
My ajax call:
$(document).ready(function(){
console.log("Ready!");
const form = document.getElementById("form");
form.addEventListener("submit", submitHandler);
function submitHandler(e){
e.preventDefault();
$.ajax({
type: 'POST',
url: '{% url "landing-home" %}',
data: $('#form').serialize(),
dataType: 'json',
success: function(data){
if(data.msg == 'Success'){
alert("Form is submitted!");
}
}
})
}
})