<%@ Page ContentType="Text/html;charset=utf-8" %><%@ include file="/web-inf/views/include/taglib.jsp"%><HTML><Head><Scripttype= "Text/javascript"src= "${ctxstatic}/jquery/jquery-1.9.1.min.js"></Script><title>Insert Title here</title><Scripttype= "Text/javascript"> functionajaxtest () {$.ajax ({data:"name="+$("#name"). Val (), type:"GET", DataType:'JSON', URL:"${ctx}/user/logindo.do", Error:function(data) {//alert ("Something went wrong!! : "+data.msg); $("#result"). HTML ("something went wrong!! :"+data.msg); }, Success:function(data) {//alert ("Success:" +data.msg); $("#result"). HTML (DATA.MSG); } }); }</Script></Head><Body> <inputtype= "text"name= "Name"ID= "Name"/> <inputtype= "Submit"value= "Login"onclick= "ajaxtest ();"/> <DivID= "Result"></Div></Body></HTML>
Controller
PackageCom.thinkgem.jeesite.modules.test.web;Importjava.io.IOException;ImportJava.util.HashMap;ImportJava.util.Map;Importjavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse;ImportOrg.springframework.stereotype.Controller;Importorg.springframework.web.bind.annotation.RequestMapping;ImportOrg.springframework.web.bind.annotation.ResponseBody;/*** Login Controller * *@authorAdministrator **/@Controller @requestmapping ("${adminpath}/user") Public classLoginsscontroller {@RequestMapping (value= "Logindo.do") Public@ResponseBody map<string,object> Login (httpservletrequest request,httpservletresponse response)throwsioexception{System.out.println (Request.getparameter ("Name")); String name= Request.getparameter ("name"); Map<String,Object> map =NewHashmap<string,object>(); if(Name = =NULL)returnmap; if(Request.getparameter ("name"). Equals ("123")) {System.out.println (Cheng Dong); Map.put ("MSG", "Success"); }Else{System.out.println (Failed); Map.put ("MSG", "Failed"); } returnmap; } @RequestMapping (Value= "Loginss.do") PublicString aaa () {return"Modules/test/aaa"; }}
Spring MVC Ajax