先引入
<script type="text/javascript" src="${baseurl}js/jquery/jquery.min.js"></script> <script type="text/javascript" src="${baseurl}js/jquery.form.min.js"></script>
GET:
$.ajax({ url : "http://www.baidu.com", //服务器地址 dataType : "json",//跨域要使用jsonp type : "GET", success : function(data){ alert('成功'); } });
或
$.ajax("http://www.baidu.com");
POST:
$.ajax({ type : "POST", url : "${baseurl}rest/login/loginout",//服务器url data : {'imgsrc':'cc'}, datatype:"json", success : function(msg) { if(msg == 200){ window.location = '${baseurl}article/query/0/list.html'; } } });
控制层:
//用户登录注销 @RequestMapping(value="loginout",method=RequestMethod.POST) public @ResponseBody String loginout(HttpServletRequest request) { HttpSession session=request.getSession(); if(session!=null){ session.invalidate(); } return "200"; }