Implement instant communication between the foreground and the background.
1. It is best to pass the action in the URL in $. Ajax by the parameter.
Front-end onload = "load ('$ (cardaction )')";
<S: URL action = "cardaction" namespace = "/examjson" includeparams = "NONE" id = "cardaction"/>
JScript
Function Load (_ URL ){
$. Ajax ({
Type: " Post " ,
URL: _ URL,
Data: " Name = " + Name,
Error: Function () {Alert ( " Error " )},
Success: Function (MSG ){
Eval ( " Res = " + MSG );
VaR Cards = Res. cards;
For ( VaR I = 0 ; I < Cards. length; I ++ ){
$ ( " # Cardselect " ). Append ( " <Option value = " + Cards [I] + " > " + Cards [I] + " </Option> " )
}
}
});
}
2. Prepare struts. xml
< Package Name = "Jsonpack" Extends = "JSON-Default" Namespace = "/Examjson" >
<! -- Get card -->
< Action Name = "Cardaction" Class = "Cardaction" Method = "Cards" >
< Result Type = "JSON" >
< Param Name = "Excludeproperties" > Employeeservice </ Param >
</ Result >
</ Action >
</ Package >
Note: employeeservice is the object to be injected in cardaction. 3. applicationcontext. xml
< Bean ID = "Addemployeeaction" Class = "Com. ambow. examonlinesystem. entity. Exam. Action. addemployeeaction" >
< Property >
< Ref Bean = "Employee" />
</ Property >
</ Bean > Java
Package Com. ambow. examonlinesystem. entity. Exam. Action;
ImportCom. ambow. examonlinesystem. entity. Exam. Interfaces. iemployee;
ImportCom. opensymphony. xwork2.actionsupport;
Public Class Cardaction Extends Actionsupport {
Private Static Final Long Serialversionuid = 163236660018615361l ;
Private String name;
Private Iemployee employeeservice;
String [] cards;
PublicString [] getcards (){
ReturnCards;
}
Public VoidSetcards (string [] cards ){
This. Cards=Cards;
}
Public VoidSetemployeeservice (iemployee employeeservice ){
This. Employeeservice=Employeeservice;
}
Public Void Setname (string name ){
This . Name = Name;
}
Public String cards (){
String [] Str = Employeeservice. getcards (name );
Cards = New String [Str. Length];
Cards = STR;
Return Actionsupport. success;
}
}
See the above cards for the data that can be obtained. The obtained method is in the load () method of the JS file.
You forgot to add jsonplugin. - 0.30 The. jar package .....