1👍
✅
You’re calling your ajax function onclick
which is why it’s working when you click on button if you want to call ajax request on enter or on click then you’ve to use onsubmit
change your code like this
$(document).ready(function(){
$('#createTaskForm').on("submit", function() {
// Get form data
let serializedData = $('#createTaskForm').serialize();
// Now pass it to TaskList view
$.ajax({
url: $("#createTaskForm").data('url'),
data: serializedData,
type: 'post',
success: function(response) {
$("#taskList").append(`${response.task.title}`)
}
})
});
});
Source:stackexchange.com