I'm trying to send two parameters using AJAX to my Spring REST controller using the POST method. However those parameters are appearing as null
in my controller. Please find the code and let me know if I'm missing anything.
var formData = {
txToClose: '1234,5678,98549',
sno: '0195'
};
$.ajax({
type: 'post',
url: url,
async: false,
data: JSON.stringify(formData),
contentType: "application/json",
dataType: "json",
success: function(result, status, xhr) {
console.log(result);
}
});
@PostMapping("/txToClose")
public ResultDto txToClose(HttpServletRequest request, HttpServletResponse response) throws BBException
{
logger.info("Called txToClose controller");
ResultDto resultDto = new ResultDto();
String txToClose = request.getParameter("txToClose");
String sno = request.getParameter("sno");
logger.info("Transactions to close :" + txToClose + ", Serial Num :" + sno);
}