I have a problem and I have no idea what the reason is. I am testing ajax requests with this code.
function sendAJAX() { var dataToSend = {}; dataToSend["username"] = $("#username").val(); dataToSend["age"] = $("#age").val(); dataToSend["date"] = $("#date").val(); $.ajax({ type : "POST", contentType : "application/json", url : "dotheajax", data : JSON.stringify(dataToSend), dataType : "json", success : function(response) { $("#typeAjaxHere").html(response); } }); } $("#form").submit(function (event) { event.preventDefault(); sendAJAX(); }) <div id="form"> <form id="user_form"> <label for="username">Name</label> <input type="text" name="username" id="username"> <label for="age">Age</label> <input type="text" name="age" id="age"> <label for="date">Birth date</label> <input type="text" name="date" id="date"> <input type="submit" value="Submit"> </form>
@Controller public class AjaxControllers { @RequestMapping(value = {"dotheajax"}, method = RequestMethod.POST) public @ResponseBody String testAjax(@RequestBody HumanDomain humanDomain) { System.out.println(humanDomain.getUsername()); System.out.println(humanDomain.getAge()); System.out.println(humanDomain.getDate()); return "Success"; } } public class HumanDomain { String username; int age; String date;
IntelliJ IDEA marks AJAX success as an “unused property success” and nothing happens, obviously, in the “success enclosure”. I really don't know why. The request works fine, in the console I get the expected result. My other similar AJAX function works, but I am not sending any JSON data, and it is GET instead of POST. Any advice would be really appreciated. Postscript Error and done also marked as unused.
source share