0
Follow
0
View

Post request work on postman but not in browser (CodeStatus : 415) - SpringBoot, thymeleaf

dqxcz1 注册会员
2023-01-25 15:37

Instead, make an AJAX call on form submit. make sure your form has an ID

$( document ).ready(function() { // SUBMIT FORM $("#form-id").submit(function(event) { // Prevent the form from submitting via the browser. event.preventDefault(); ajaxPost(); }); function ajaxPost(){ // PREPARE FORM DATA var formData = { firstname : $("#firstName").val(), lastname : $("#lastName").val(), --------other attributes with values--------- } // DO POST $.ajax({ type : "POST", contentType : "application/json", url : "/registration", data : JSON.stringify(formData), dataType : 'json', success : function(result) { ----redirect to another url---- console.log(result); }, error : function(e) { alert("Error!") console.log("ERROR: ", e); } }); // Reset FormData after Posting resetData(); } function resetData(){ $("#firstname").val(""); $("#lastname").val(""); }

})

About the Author

Question Info

Publish Time
2023-01-25 15:37
Update Time
2023-01-25 15:37

Related Question