I've been encountering a persistent error 415 whenever I try to send a post request to the server, despite trying numerous solutions without success.
Here is my JavaScript code:
var form = $('form')[0];
var formData = new FormData(form);
$.ajax({
method: "POST",
url: "./signup",
data: formData,
enctype: 'multipart/form-data',
cache: false,
contentType: false,
processData: false,
success : function(data) {
//...
},
error : function(qXHR, textStatus, errorThrown){
console.log(errorThrown, "Error " + qXHR.status);
}
});
And here is the HTML code snippet:
<form id="signup-form" action="#">
<div class="form-group">
<label>First Name</label>
<input name="firstName" type="text" id="firstName">
</div>
<div class="form-group">
<label>Surname</label>
<input name="surname" type="text" id="surname">
</div>
<div class="form-group">
<label>File</label>
<input type="file" name="attachFile" id="attachFile">
</div>
</div>
<input type="submit" id="btn-submit-signup value="Submit">
</form>
In addition, I have the following Java code:
//controller header
@RequestMapping(value = "/signup", headers = "content-type=multipart/*", method = RequestMethod.POST)
public @ResponseBody Response<String> signup(@RequestBody UserSignup details)
//UserSignup
public class UserSignup {
private String firstName;
private String surname;
private MultipartFile attachFile;
public UserSignup(){}
//getters and setters...
}
Does anyone know what could be causing this issue?