$.get(),$.ajax(),$.getJSON()代码中简单使用
来源:互联网 发布:厘米换算英尺英寸c语言 编辑:程序博客网 时间:2024/06/05 08:15
controller中的代码
@RequestMapping("/getCnt")
@ResponseBody
public Long getCnt(){
return 24214L();
}
jsp中页面两种方法的实现,ajax功能比较强大,可以指定类型
(1):
$.getJSON("getCnt",function(data){
$("#cnt_display").html("需要的long类型的值:" + data);
});
(2):
$.ajax({
url:'getCnt',
type:'post',
success:function(data){
var res=data.result;
$("#cnt_display").html("需要的long类型的值:" + data);
console.log("需要的long类型的值:"+data)
}});
<form action="*.do" id="form" name="form" method="post">
<a class='btn btn-mini btn-info' title="标记" onclick="changeStatus('${pg.id }');">标记</a>
</form>
function changeStatus(id){
$.get("*.do?id="+id,function(data){
//提交表单
$("#form").submit();
});
}
java后台的代码
@RequestMapping(value = "/*.do")
public ModelAndView weiduListPage(HttpServletRequest request, int id) {
ModelAndView mv = new ModelAndView();
·············;
return mv;
}
@RequestMapping("/getCnt")
@ResponseBody
public Long getCnt(){
return 24214L();
}
jsp中页面两种方法的实现,ajax功能比较强大,可以指定类型
(1):
$.getJSON("getCnt",function(data){
$("#cnt_display").html("需要的long类型的值:" + data);
});
(2):
$.ajax({
url:'getCnt',
type:'post',
success:function(data){
var res=data.result;
$("#cnt_display").html("需要的long类型的值:" + data);
console.log("需要的long类型的值:"+data)
}});
<form action="*.do" id="form" name="form" method="post">
<a class='btn btn-mini btn-info' title="标记" onclick="changeStatus('${pg.id }');">标记</a>
</form>
function changeStatus(id){
$.get("*.do?id="+id,function(data){
//提交表单
$("#form").submit();
});
}
java后台的代码
@RequestMapping(value = "/*.do")
public ModelAndView weiduListPage(HttpServletRequest request, int id) {
ModelAndView mv = new ModelAndView();
·············;
return mv;
}
阅读全文