@RequestMapping(value = "/ajaxtest", method = RequestMethod.GET)
public @ResponseBody
String getTime() {
Random rand = new Random();
float r = rand.nextFloat() * 100;
String result = "<br>Next Random # is <b>" + r + "</b>. Generated on <b>" + new Date().toString() + "</b>";
System.out.println("Debug Message from CrunchifySpringAjaxJQuery Controller.." + new Date().toString());
return result;
}
@RequestMapping(value = "profile", method = RequestMethod.GET)
public @ResponseBody String processAJAXRequest(@RequestParam("regnum") String regnum, ModelMap map)
{
/*System.out.println(regnum);
System.out.println(studentService.studentRegNo(regnum));*/
boolean b= studentService.studentRegNo(regnum);
if(b==true)
{
return "Give the Different Reg number";
}
else
{
return "Enter";
}
}
IN JSP
<script type="text/javascript">
function crunchifyAjax() {
var regnum = $('#regnum').val();
/* alert(regnum); */
var data = 'regnum='
+ encodeURIComponent(regnum);
/* alert("inside ajax"); */
$.ajax({
url : 'profile.html',
data : data,
success : function(data) {/* alert(data); */
$('#result').html(data);
}
});
}
</script>
<td><form:label path="regnumber">Registration Number<span class="mandatory">*</span></form:label></td>
<td>
<form:input path="regnumber" class="textFLD" required="required" onblur="crunchifyAjax();" id="regnum"/></td>
<td width="40%"><div id="result" class="message" ></div></td>
我已经发布了我的控制器和jsp页面,请帮我清除我的文本框,如果重复输入到regnum字段现在当输入重复项时显示消息但我也想清除文本框。
答案 0 :(得分:0)
尝试此操作以清除输入:
/* alert("inside ajax"); */
$.ajax({
url : 'profile.html',
data : data,
success : function(data) {/* alert(data); */
if(data=='Give the Different Reg number'){
$('#regnum').val('');
}
else {
$('#result').html(data);
}
}
});