ajax方法:$.ajax( { type : "POST", url : "/home/user/login.htm", //訪問路徑 data : {name: name, title: title}, //引數 success : function(msg) { if (msg == 1) { } else { } }, error:function(msg){ alert("程式出錯,請聯絡管理員"); }});java類方法:@RequestMapping("user/login.htm")public String getAddGroupsAjax(String name,String title) throws Exception{ HttpServletResponse response = getResponse(); response.setContentType("text/html;charset=UTF-8"); PrintWriter pw = null; //方法處理,最後返回一個字元竄,來判斷是成功還是失敗了 try { pw = response.getWriter(); pw.print(str); } catch (IOException e) { //錯誤處理 }finally{ pw.close(); } return null;}
ajax方法:$.ajax( { type : "POST", url : "/home/user/login.htm", //訪問路徑 data : {name: name, title: title}, //引數 success : function(msg) { if (msg == 1) { } else { } }, error:function(msg){ alert("程式出錯,請聯絡管理員"); }});java類方法:@RequestMapping("user/login.htm")public String getAddGroupsAjax(String name,String title) throws Exception{ HttpServletResponse response = getResponse(); response.setContentType("text/html;charset=UTF-8"); PrintWriter pw = null; //方法處理,最後返回一個字元竄,來判斷是成功還是失敗了 try { pw = response.getWriter(); pw.print(str); } catch (IOException e) { //錯誤處理 }finally{ pw.close(); } return null;}
以上最少需要你懂一些springMVC,不然的話我也沒辦法