Using jQuery for avoid form action caught error
Hi i want to save data standard name to database using jquerry with not
reqired 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
with regards
Milano
No comments:
Post a Comment