The below is a working example. Add async:false
.
const response = $.ajax({
type:"POST",
dataType:"json",
async:false,
url:"your-url",
data:{"data":"data"}
});
console.log("response: ", response);