To achieve an effect is to select a year: Then the action in the year to find data in the database, returned to the page form display.
1. Add the Changge event for the registration year, which is also an asynchronous request.
$ (document). Ready (function () {$ ("#registYear"). Change (function () {$.ajax ({//Background Processing programUrl:"findthesis.action", //How data is sentType:"Post", //Receive data FormatDataType:"JSON", //the data to be passedData:"registyear="+$("#registYear"). Val (),//callback functionTimeout20000,//sets the request time-out (in milliseconds). Error:function () {//The function is called when the request fails. Alert"request failed"); }, Success:function (data) {//The callback function after the request succeeds. //location= "person-thesis.jsp"; //alert (data.htmldata);$("#thesisList"). Append (Data.htmldata); } }); }); });
Note: The datatype here should be JSON.
2. Define a htmlstring string in action. and add the Get set method. This allows you to get the data returned by the action in success: 's data.
Then stitch the htmlstring string in action:
list<personthesis> list = personthesisbiz.findbyregistyear (application.Get("ID"). ToString (), registyear); if(List.size () >0) {personthesis personthesis; StringBuffer Buffer=NewStringBuffer (); Buffer.append ("<tr class=\ "demo\" ><td>"); for(intI=0; I<list.size (); i++) {personthesis= list.Get(i); Buffer.append (i+"</td><td>"+personthesis.getthesisname () +"</td><td>"+personthesis.getthesisquality ()). Append ("</td><td>"+personthesis.getjournal () +"</td><td>"+personthesis.getnum () +"</td><td>"). Append (Personthesis.gettime ()+"</td><td>"+personthesis.getthesistype () +"</td><td>"). Append (Personthesis.getgrade ()+"</td><td>"+personthesis.getremark () +"</td>"). Append ("<td><a href=\ "findthesis.action?index="+i+"id=\ "Thesis\" > Edit </a></td>"). Append ("<td><a href=\ "findthesis.action?index="+i+"id=\ "thesis\" > Delete </a></td></tr>"); } htmldata= Buffer.tostring ();
3. When configuring the action in Struts.xml, configure the method as follows:
<package name= programinjection extends=" json-default > <action name="
findthesis class = Stdu.edu.cn.web.action.FindThesisAction method= " find " > <result type= " json " ></result> </action> </package>
4. When the return succeeds, add the row dynamically, then you can
jquery Dynamic Refresh Local form