This is a simplified version of a problem I'm having. How do I send data to a Spring Boot Controller via an AJAX Query and then open a new JSP page? When I send data to the url
in the AJAX Query to the matching URL in my controller class it seems to run the code within that method but not open the JSP (or return type).
For example if I were to send the following data from an Ajax Query
var hello = "Hello World!";
$.ajax({
type: "POST",
url: "/message1",
data: {
message: hello,
},
datatype: 'json'
});
}
To this method in my Controller class
@RequestMapping(value = "/message1", method = RequestMethod.POST)
public String MessageReceiver(@RequestParam("message")String message,
BindingResult bindingResult,
Model model) {
System.out.println(message);
return "NewPage";
}
"Hello"
will print in the console but the JSP page NewPage
will fail to open and will prompt no errors?
Usually if I just call the url in the controller (for example /message1
) via a href link, or button etc the NewPage
JSP page will open. It seems that the AJAX query is missing something. Do I have to update the URL in the Ajax Query to something similar to /message1/NewPage
(tried this, didn't work), or add something to the controller because the NewPage
JSP page will not open.
Add the success callback function to your ajax like so:
$.ajax({
type: "POST",
url: "/message1",
data: {
message: hello,
},
datatype: 'json',
success: function(data){
if(data === "NewPage"){
//Open new page
}
}
});
}
Firebase Cloud Functions: PubSub, "res.on is not a function"
TypeError: Cannot read properties of undefined (reading 'createMessageComponentCollector')
I planned to start making an average sized RWD web site with ability to access DB data via cross domain optionPlan also include nice and smooth access with classic computers and tablets, mostly 10" diagonals
I am working on a project where I will provide the facility to the user to store the video files into the databaseSo later on the application will show all of the uploaded video files
How is it possible to pass an array of elements as well as keeping the data attributes using jQuery? currently I've got the following:
I am trying to call my php controller function using javascript and jquery but I am not reaching the function