ajax+struts2

Do the cascade query
Use ajax when select value change calling action returns a JSON format data and the data extracted from display page code in another drop of page frame:
	The receiving department:<select name="dept" style="width:100px" id="dept">
				<s:iterator id="list" var="list" value="list">
					<option value="<s:property value='id'/>"><s:property value="name"/></option></s:iterator>
				</select>
				 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
				Reception staff:<select name="opeUserCode" id="opeUserCode">
					
				</select> 

The Ajax code is as follows:
 $("#dept").change(
					function() {
						$.ajax({
								type : "post",//Use the get method to access the background
								dataType : "json",//Returns the data in text format
								url : "hlb_getDeptUser.action",//To access the backend.
								data : "dept="+ $("#dept").val(),//The data to be transmitted
								async : true,
								/*complete : function(data) { },*/
								success : function(data) { //MSG for the returned data, do the data binding in here
									var userId;
									var userName;
									$(data,function(i) {
										var sj = data[i];
										userId = sj[0];
										userName = sj[1];
										
										$("#opeUserCode").append(
												"<option value='"+userId+"'>"+userName+"</option>"
										);
									});
								}
						});
					});

The code is as follows:
Connection conn = ConnectionManager.getDssConn();
		DBManager dbManager = new DBManager(conn);
		ResultSet rs = null;
		String sql = "";
		List list = new ArrayList();
		try {

			sql = "select dept_id,dept_name from env_t_department where zt=1";
			rs = dbManager.sqlSelect(sql);
			while(rs.next()){
				DeptObject obj = new DeptObject();
				obj.setId(rs.getString("dept_id"));
				obj.setName(rs.getString("dept_name"));
				list.add(obj);
			}

		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			ConnectionManager.closeConn(conn);
		}
response.setCharacterEncoding("utf-8");
			try {
				response.getWriter().write(JsonUtil.list2json(list));
			} catch (IOException e) {
				e.printStackTrace();
			}

JsonUtil.list2json is a method of conversion has been packaged format.
In the success: function (data) {//msg for the returned data, do the data binding in here
var userId;
var userName;
$(data,function(i) {
var sj = data[i];
userId = sj[0];
userName = sj[1];

$("#opeUserCode").append(
"<option value='"+userId+"'>"+userName+"</option>"
);
});Has entered the success, but not to perform for help

Started by Katherleen at November 09, 2016 - 4:22 AM

Ask for help

Posted by Katherleen at November 21, 2016 - 5:04 AM

There is no information error, where

Posted by Fred at November 28, 2016 - 5:47 AM

If there is no error information, and use the struts JSON return, estimation is because of the internal depth sequence problem, can not complete the sequence of operation, json-plugin tools you can use the struts, sequence object into a string, and then response to the page, and then in the page using the eval method to convert a string into a JSON object

Posted by Bonnie at December 02, 2016 - 6:42 AM

You see whether your struts configuration file returns JSON, if action returns JSON

Posted by Jonathan at December 16, 2016 - 7:08 AM