I am using jQuery to send an AJAX POST request. If successful, I need to redirect the user to another page, if I refuse, I want to stay on the page with the same data.
I have 2 questions.
- In SUCCESS it is not redirected, it stays at the same URL and gives 415
- In FAILURE, I get 415 instead of the page I get.
Here is my code:
var jsonResponse = [];
var req = {
"name" : "${name}",
"id" : "${id}",
"data" : jsonResponse
};
$.ajax({
url: "url",
type: "POST",
dataType: 'json',
contentType:'application/json',
async: false,
data: JSON.stringify(req),
success: function(result) {
url = window.location.href;
url = url.replace("processData", "getData");
alert(url);
location.href = url;
},
error: function() {
alert("--- Failure ---");
}
});
Controller for url1
@RequestMapping(value = "processData", method = RequestMethod.POST)
public String post( Model model,
HttpServletRequest httpServletRequest,
@RequestBody FormModel model) {
}
Controller for url2:
@RequestMapping(value = "getData", method = RequestMethod.GET)
public String get(Model model, HttpServletRequest httpServletRequest)
{
}
I am adding a snapshot of the error message that I am receiving.

What am I doing wrong here?
source
share