ตัวอย่างนี้แบ่งปันรหัสเฉพาะสำหรับ jQuery เพื่อรับรู้การเชื่อมโยงสามระดับสำหรับการอ้างอิงของคุณ
ส่วนหน้า JSP:
<li id = "floors"> <span id = "floorshow"> เลือกอาคาร: </span> <select name = "build" id = "build" onchange = "floor2 ()"> </select> </li> <li id = "builds"> <span id = "floorshow">
JS Part:
Function Floor () {document.getElementById ("build"). ตัวเลือก. length = 0; E: "JSON", ความสำเร็จ: ฟังก์ชั่น (ข้อมูล) {console.log (ข้อมูล); data.length; GetElementById ("floot2"). ตัวเลือก. length = 0; : "โพสต์", url: "floor2.action", ข้อมูล: {"parentid": build}, ข้อมูล: "json", ความสำเร็จ: ฟังก์ชั่น (ข้อมูล) {var len = data.length; ] .info+"</optup>";} $ ("#floot2").ส่วนการกำหนดค่า Struts2:
<package name = "user" namespace = "/" extref = "json-default"> <action name = "floor" method = "floor"> <result type = "json"> <param name = "root"> floor </param> </result> </action> <action name = "floor2" method = "floor2"> <
ส่วนการดำเนินการ:
สตริงสาธารณะ () {System.out.println ("นี่คือ Ajax Call"); .println ("นี่คือการเรียก Ajax ครั้งที่สอง"); System.out.println (addressInfo.getParentId ());ในที่สุดอย่าลืมนำเข้า struts2-json-plugin-2.3.15.1.jar
ข้างต้นเป็นเนื้อหาทั้งหมดของบทความนี้