jquery Dynamic Refresh Local form

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.