I'm fairly new to programming, and I'm trying to fix a slight bug I've encountered. My data is supposed to be posted to the an API when I press the submit button, but when I use the button, the page just refreshes. When I preserve the logs from the console, I can see that the call IS being made, but it's being canceled before it can be posted. I'm using a live server to test out my code.
let URL = "https://6327494d5731f3db9956d362.mockapi.io/users";
$("#submitButton").on("click", (event) => {
if (event.preventDefault) {
let firstName = $("#firstName").val();
let lastName = $("#lastName").val();
let emailAddress = $("#emailAddress").val();
console.log(firstName, lastName, emailAddress);
$.ajax({
url: URL,
data: JSON.stringify(firstName, lastName, emailAddress),
dataType: "json",
type: "POST",
contentType: "application/json",
crossDomain: true,
});
}
});
Thank you in advance for any suggestions.