To introduce jquery on the JSP
<script src="<%=request.getcontextpath ()%>/js/jquery_ui/jquery.js"></ Script>
Initiating a request in JS
functionGet(p) {varPatch="Show"+p; $.ajax ({//This is the $.ajax () methodType"POST", Url:patch,//The path can be in relative path, and the starting point is the path shown in the JSP where this method residesData: $ ('#myform'). Serialize (),//Ajax Submission FormDataType:"HTML",//The data type that accepts the response, my response is a page, so here's the "HTML"success:function (data) {$ ('#mydiv'). HTML (data);//I put the response page in a div to show } }) }
MyForm is a form tag in the JSP Id,mydiv is a div id,ajax to display the location of the JSP in the middle of this div, remember to add these two in the JSP
<form id="myform" method="post" > <input id= " Hidden " name="ID" type="hidden" Value=${id} > </form><div id="mydiv"> </div>
MyForm normally initiates a SPRINGMVC request, controller returns to a JSP normally
I did not do the following step, but the normal display.
Add @ResponseBody comment to the Controller's method of accepting paths
@ResponseBody// function is to send the returned object as a response to the page "/showaj" ) Public string Toindex (string ID, model model) { return"AJ"; }
Javaweb Local Refresh-ajax asynchronous request SPRINGMVC display the returned JSP content instead of the IFRAME