I am trying to submit a form using JQuery but it does not seem to be submitting. What am I doing wrong? This is my JS code: It does not log the hello
word.
document.querySelector("form#myForm").addEventListener('submit', validateForm)
function validateForm(e)
{
e.preventDefault();
var values = $('#myForm').serialize();
$.ajax({
url: "<?php echo route('validate') ?>",
method: 'GET',
async:false,
data: values,
success: function(data) {
var data = JSON.parse(data);
var text = data.text;
var image_url = data.image;
swal({
html: "<div style='text-align: left; margin-left: 10px'><strong>Preview</strong></div>",
showCancelButton: true,
confirmButtonText: "Yes",
cancelButtonText: "No",
confirmButtonColor: "#00ff55",
cancelButtonColor: "#999999",
reverseButtons: true,
}).then((result) => {
if (result.value) {
$("#myForm").submit(function(e){
console.log('hello')
});
}
});
}
});
return false;
}
This is the form
opening tag attributes - <form action="{{url('test')}}" method="post" onsubmit="return validateForm(e);" id="myForm" name="a-form">