I have a web application that is developed in jquery and spring mvc...all is working perfectly...but now I want to use React JS in my application...i want to create a form in react js and send ajax request to my spring mvc controller...I know how to do it with jquery but not with react js....kindly tell me a way to create a form and send a request to the spring mvc controler.... this is my controller method where I want to get request...
@RequestMapping(value = "/saveuser", method = RequestMethod.POST)
public @ResponseBody String Save(/*@Valid Users user, BindingResult result,*/HttpServletRequest request, Model model,
@RequestParam(required = false) Boolean reverseBeforeSave) {
String userName = request.getParameter("username");
String password = request.getParameter("password");
String firstName = request.getParameter("first_name");
String lastName = request.getParameter("last_name");
System.out.println("save method");
String[] roleNames = request.getParameterValues("roles");
userService.saveUserandRoles(userName, password, firstName, lastName, roleNames);
return "success";
}
I went through different solutions in StackOverflow and have searched on google but I am not getting any proper result.
Install axios
$ npm install axios
Import axios
import axios from 'axios';
Example GET request
axios.get('https://api.example.com/')
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
Example POST request
var body = {
firstName: 'testName',
lastName: 'testLastName'
};
axios.post('https://api.example.com/', body)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With