How to achieve dynamic acquisition of Jquery drop-down box data
This time I will show you how to implement the dynamic acquisition of Jquery drop-down box data. What are the precautions for the dynamic acquisition of Jquery drop-down box data. The following is a practical case, let's take a look.
Without further ado, let’s go directly to the source code:
select.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>" rel="external nofollow" > <title>My JSP 'select.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css" rel="external nofollow" > --> <script type="text/javascript" src="js/jquery-2.1.1.min.js" charset="utf-8"></script> <script type="text/javascript"> function get_app_type() { $.ajax({ type: "post", url: "AppTypeShow.action", //获取json数据 dataType: "json", success: function(data) { var d = eval("(" + data + ")"); for(var i = 0; i < d.length; i++) { var id = d[i].id; var name = d[i].name; var opt = "<option value='" + id + "'>" + name + "</option>"; $("#appType").append(opt); } }, error: function() { alert("系统异常,请稍后再试!") } }); } function get_app_class() { $.ajax({ type: "post", url: "AppClassShow.action", dataType: "json", success: function(data) { var d = eval("(" + data + ")"); for(var i = 0; i < d.length; i++) { var id = d[i].id; var name = d[i].name; var opt = "<option value='" + id + "'>" + name + "</option>"; $("#appClass").append(opt); } }, error: function() { alert("系统异常,请稍后再试!") } }); } $(document).ready(function() { get_app_type(); get_app_class(); }); </script> </head> <body> <table> <tr> <td align="right">APP类型:</td> <td align="left"> <select name="appType" id="appType" style="margin-left: 16px; height: 30px; width: 110px; text-align: left; size: 3; color: #505050;"> <option value="-1">---请选择---</option> </select> </td> </tr> <tr height="25px"><td> </td></tr> <tr> <td align="right">APP种类:</td> <td align="left"> <select name="appClass" id="appClass" style="margin-left: 16px; height: 30px; width: 110px; text-align: left; size: 3; color: #505050;"> <option value="-1">---请选择---</option> </select> </td> </tr> </table> </body> </html>
struts .xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <constant name="struts.i18n.encoding" value="UTF-8"></constant> <package name="simpleton" extends="struts-default,json-default"> <action name="*JsonAction" method="{1}" class="jquery.chisj.action.JsonAction"> <result name="fail">error.jsp</result> <result type="json"> <param name="root">result</param> </result> </action> <action name="AppTypeShow" class="jquery.chisj.action.NtAppAction" method="appTypeShow"> <result name="fail">error.jsp</result> <result type="json"> <param name="root">result</param> </result> </action> <action name="AppClassShow" class="jquery.chisj.action.NtAppAction" method="appClassShow"> <result name="fail">error.jsp</result> <result type="json"> <param name="root">result</param> </result> </action> </package> </struts>
NtAppAction.java
/** * */ package jquery.chisj.action; import java.util.ArrayList; import java.util.List; import jquery.chisj.entity.APPClass; import jquery.chisj.entity.APPType; import com.opensymphony.xwork2.ActionSupport; import net.sf.json.JSONArray; /** * @ClassName: NtAppAction * @Description: TODO * @Author: chisj chisj@foxmail.com * @Date 2016年1月20日 下午4:53:50 */ public class NtAppAction extends ActionSupport { private String result; public String appTypeShow() { System.out.println("---app type show---"); List<APPType> appTypeList = new ArrayList<APPType>(); try { APPType appType_1 = new APPType(); APPType appType_2 = new APPType(); appType_1.setId(Short.valueOf("1")); appType_1.setName("Android"); appType_2.setId(Short.valueOf("2")); appType_2.setName("iOS"); appTypeList.add(appType_1); appTypeList.add(appType_2); JSONArray jsonArray = JSONArray.fromObject(appTypeList); result = String.valueOf(jsonArray); } catch (Exception e) { e.printStackTrace(); } return SUCCESS; } public String appClassShow() { System.out.println("---app class show---"); List<APPClass> appClassList = new ArrayList<APPClass>(); try { APPClass appClass_1 = new APPClass(); APPClass appClass_2 = new APPClass(); appClass_1.setId(Short.valueOf("1")); appClass_1.setName("种类1"); appClass_2.setId(Short.valueOf("2")); appClass_2.setName("种类2"); appClassList.add(appClass_1); appClassList.add(appClass_2); JSONArray jsonArray = JSONArray.fromObject(appClassList); result = String.valueOf(jsonArray); } catch (Exception e) { e.printStackTrace(); } return SUCCESS; } public String getResult() { return result; } public void setResult(String result) { this.result = result; } }
I believe you have mastered the method after reading the case in this article, more Please pay attention to other related articles on the php Chinese website!
Recommended reading:
jQuery and vue make the verification code effect of drag verification
$.ajax() How to get json data from the server
The above is the detailed content of How to achieve dynamic acquisition of Jquery drop-down box data. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



When creating a virtual machine, you will be asked to select a disk type, you can select fixed disk or dynamic disk. What if you choose fixed disks and later realize you need dynamic disks, or vice versa? Good! You can convert one to the other. In this post, we will see how to convert VirtualBox fixed disk to dynamic disk and vice versa. A dynamic disk is a virtual hard disk that initially has a small size and grows in size as you store data in the virtual machine. Dynamic disks are very efficient at saving storage space because they only take up as much host storage space as needed. However, as disk capacity expands, your computer's performance may be slightly affected. Fixed disks and dynamic disks are commonly used in virtual machines

Google Authenticator is a tool used to protect the security of user accounts, and its key is important information used to generate dynamic verification codes. If you forget the key of Google Authenticator and can only verify it through the security code, then the editor of this website will bring you a detailed introduction on where to get the Google security code. I hope it can help you. If you want to know more Users please continue reading below! First open the phone settings and enter the settings page. Scroll down the page and find Google. Go to the Google page and click on Google Account. Enter the account page and click View under the verification code. Enter your password or use your fingerprint to verify your identity. Obtain a Google security code and use the security code to verify your Google identity.

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

Although the general operations of domestic mobile phones are very similar, there are still some differences in some details. For example, different mobile phone models and manufacturers may have different dual-SIM installation methods. Erzhenwo 12Pro, a new mobile phone, also supports dual-SIM dual standby, but how should dual-SIM be installed on this phone? How to install dual SIM on Realme 12Pro? Remember to turn off your phone before installation. Step 1: Find the SIM card tray: Find the SIM card tray of the phone. Usually, in the Realme 12 Pro, the SIM card tray is located on the side or top of the phone. Step 2: Insert the first SIM card. Use a dedicated SIM card pin or a small object to insert it into the slot in the SIM card tray. Then, carefully insert the first SIM card.

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: <

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

Many players want to know how to obtain fake future crystal coins. There are actually four different methods, including purchasing gift packages, completing tasks, producing goods, developing land, etc. Players can choose different ways to earn crystal coins according to their needs. The specific content is as follows: Get up and take a look at this guide on how to obtain fake future crystal coins. Fake Future Guide: How to get Fake Future Crystal Coins 1. Purchase the gift package mall to purchase the crystal coin gift package. 2. Obtained by completing tasks and completing main and side tasks. 3. Produce goods. Produce goods in your home to obtain crystal coins. 4. Developing land can also be obtained by developing land, but the reward is one-time.

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute
