The parameters passed in the request's Ajax path (data) will be received by a variable with the same name (with the set get method) in the action. The returned data is a jquery array object, the data variables involved in the called action will be objects and will be encapsulated in data and finally returned to the page.
Case :,
I want to change the status. After jquery Ajax is used, the icon changes to partially refresh the page.
Principle: Partial refresh is part of the page refresh. In this case, only the icon changes are implemented, and the background code is separated from the icon in the foreground reality, instead of re-querying the database, second, after the digital display data in the background is modified, the foreground changes the icon directly.
1. The page provides a unique ID value for the icon of each record:
<TD align ="Center">
<S: If test ="Messagestate = 0">
<IMG src ="$ {CTX}/Images/04.png"Id ="R$ {Message. messageid}"/>
</S: If>
<S: else>
<IMG src ="$ {CTX}/Images/03.png"Id ="R$ {Message. messageid}"/>
</S: else>
</TD>
Ajax verification: add the id = aunread to the a tag, and then add the event
Jquery ("# aunread"). Click (Function(){
VaRStrids = ""; // defines a variable for data transmission.
$ ("Input [name = 'checkbox']"). Each (Function(){
If(This. Checked ){
Strids + =This. Value + ","; // you can obtain Multiple ID values and splice them into strings to upload them to the action.
}
});
$. Ajax ({
Type: "Post ",
Datatype: 'json', // accept the data format
Cache:False,
Data: "strids =" + strids,
URL: "$ {CTX}/feedbackonline/updatemessagestateunread. Action ",
Beforesend:Function(XMLHttpRequest ){
},
Success:Function(Data ){
VaRSTR = data. STR; // receives the returned data
For(VaRP
InStr) {// traverse the accepted array object
VaRX = "# R" + STR [p]; // retrieve the icon ID of the record to be changed
$ (X). ATTR ("src", "$ {CTX}/images/04.png ");
// Change the src attribute value of the corresponding id value to the path of the corresponding icon
}
},
Error:Function(){
// Handle request errors
Alert ("error! ");
}
});
});
2. Background action:
PrivateString strids; // The set get method is omitted to automatically obtain the response data from the page.
PrivateString [] STR; // omitting the set get Method
@ Action ("/updatemessagestateunread ")
PublicString updatemessagestate ()ThrowsException {
String [] jstr = strids. Split (","); // splits the string into a string array.
STR = jstr; // assign the split string array to the array variable STR with the Get Set Method and return it to the page.
For(IntI = 0; I <jstr. length; I ++ ){
IntId = integer.Parseint(Jstr [I]);
Messageuserinfo = messageuserinfomanager. querybyid (ID );
Messageuserinfo. setmessagestate (0 );
Messageuserinfomanager. Update (messageuserinfo );
}
Return"Ajax ";
}