Company-->ajax Get Data

Source: Internet
Author: User
Tags json

JS content:

/** gets the Department list through the section ID */
function Getdepartmentlistbysectionidfun () {
	var sectionid=$ ("#sectionId"). Val ();
	var defvalue = $ ("#departmentId"). attr ("Defvalue");
	$ ("#departmentId"). empty ();
	$.ajax ({
		type: "Post",
		Url:contentpath + "/ajax/getdepartmentlistbysectionid.do",
		data: {
			Sectionid:sectionid
		},
		Async:false,
		dataType: "JSON",
		success:function (data) {
			if (data) {
				var arr=eval (data);
				for (var i = 0; i < arr.length; i++) {
					$ ("#departmentId"). Append ("<option value = '" +arr[i].departmentid+ "' > "+arr[i].departmentname+" </option> ");
				}
				if (defvalue) {
					$ ("#departmentId"). Find ("Option[value = '" +defvalue+ "']"). attr ("Selected", "selected");
				}
			}
		}
	});
	Showiephandiepersons ();
}


Action content:

Package Gts.erp.action.ajax;

Import gts.erp.action.base.ERPProxyAction;

Import Java.io.PrintWriter;
Import Javax.servlet.http.HttpServletRequest;

Import Javax.servlet.http.HttpServletResponse;
Import Net.sf.json.JSONArray;

Import Net.sf.json.JSONObject;
Import Org.apache.struts.action.ActionForm;
Import Org.apache.struts.action.ActionForward;

Import org.apache.struts.action.ActionMapping;
Import Com.oletech.triangle.component.CellBean;
Import Com.oletech.triangle.component.FormBean;

Import Com.oletech.triangle.utils.TriangleUIHelper; /** * * Get Department list by Section ID * @author OLE * * */public class Getdepartmentlistbysectionidaction extends Erpproxyaction {@ Override protected Actionforward Doexecute (Formbean PARAMETERFB, actionmapping Mapping, Actionform form, HttpServletRequest request, HttpServletResponse response) throws Exception {Formbean Formbean = This.geterpservicede
		
		Legation (). Getmasterproductionscheduleservice (). Getdepartmentbysection (PARAMETERFB); Jsonarray JSONArray = new Jsonarray ();
			for (int i = 0; i < formbean.size (); i++) {Cellbean Cellbean = Formbean.get (i);
			Jsonobject jsonobject = new Jsonobject ();
			Jsonobject.put ("DepartmentID", Cellbean.getkey ());
			Jsonobject.put ("Departmentname", triangleuihelper.getmessageresources (Request, Cellbean.getvalue ()));
		Jsonarray.add (Jsonobject);
		} printwriter pw = Response.getwriter ();
		Pw.print (Jsonarray);
		Pw.flush ();
	return null;
 }

}


Impl content:

/** * According to section Inquiry Department * @author Zhuyz * @date November 19, 2016 17:45:16 * @param databean * Formbean = key: "Para METERFB "* Cellbean Key:sectionid * @return Formbean * Formbean key:errormsg * Tablebean =&G T Key: "Tn_department" * cellbean key:cn_id,cn_name .... * Tablebean = + key: " Tn_department_iesetup "* Cellbean key:cn_id,cr_department_id ... * * * Publ
		IC Formbean getdepartmentbysection (Formbean formbean) {String SectionID = Formbean.getcellbeanvalue ("SectionId");
		Formbean RETURNFB = new Formbean ();
				try {if (Stringutils.isnotempty (SectionID)) {Condsetbean CSB = new Condsetbeanjustand ();
				Csb.addcondbean (New Condbeanequal ("cr_section_id", SectionID));
				Tablebean Tablebean = This.baseDAO.queryForTableBean (New Classpojo ("Tn_department_iesetup"), CSB);
				Condsetbean csbdepartment = new Condsetbeanjustand (); Condbeanin Cbidepartment = new Condbeanin (triangledefinition.column_name_cn_id); for (int i = 0; i < tablebean.size (); i++) {Cbidepartment.addvalue (Tablebean.get (i). Getcellbeanvalue ("Cr_departme
				nt_id "));
					} if (Cbidepartment.size () > 0) {csbdepartment.addcondbean (cbidepartment);
					Tablebean DEPARTMENTTB = This.baseDAO.queryForTableBean (New Classpojo ("Tn_department"), csbdepartment);
						for (int i = 0; i < departmenttb.size (); i++) {Rowbean Rowbean = Departmenttb.get (i); Returnfb.addcellbean (New Cellbean (Rowbean.getcellbeanvalue (triangledefinition.column_name_cn_id), RowBean. GetCel
					Lbeanvalue (Triangledefinition.column_name_cn_name));
			}}}} catch (Exception e) {triangleblhelper.printexceptionlog (log, E);
			E.printstacktrace (); throw New RuntimeException (* * * * Run time Exception.
		****");
	} return RETURNFB; }


Related Article

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.