I want to save data standard name to database using jQuery with not required form th:action and redirection.
I tried with this but caught error.
If you know the reason for this error please explain here.
Thymeleaf code
<form action="#" >
<table>
<h1>Create Standard</h1>
<tr>
<td>Standard Name:</td>
<td><input type="text" th:value="${standardName}" placeholder="Enter Standard Name" required="required"id="std" name="stdName"/></td></tr>
<td><input type="submit" class="btn btn-primary" value="Create" id="savebutton" name="save" /></td>
</table>
</form>
I am using jQuery because of the redirect and form actions are not working here. That's my requirement, so I use jQuery.
jquery
<script type="text/javascript" th:inline="javascript" charset="utf-8"
src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript" th:inline="javascript" charset="utf-8"
src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(document).ready(function(){
$("#savebutton").click(function(){
$.ajax({
type : 'POST',
url : "/saveStandards.html ",
data : ({
std : standardName //this standardName not defined that is the error
})
});
});
});
</script>
Controller
@RequestMapping(value = Array("/saveStandards.html"))
@ResponseBody
def saveStandards(@RequestParam std:String) {
var standard:Standard=new Standard
standard.setCreatedDate(new java.sql.Date(new java.util.Date().getTime))
standardService.addStandard(standard)
println("*****inside controller*****"+std+"****last***")//here std is not printing because of the value not catch @ here
}
error caught:
Uncaught ReferenceError: standardName is not defined