Sample Code for jquery. post usage

Source: Internet
Author: User

Use ajax to verify whether an operation is performed on the frontend
The jquery. post parameter is
Url, [data], [callback], [type]

Url: The sending request address.

Data: Key/value parameter to be sent.

Callback: callback function when sending successfully.

Type: The returned content format is xml, html, script, json, text, and _ default.
Copy codeThe Code is as follows:
$. Post ('admin/HhCheckVote. do? Ids = '+' $ {ids} ', {}, function (flag ){
If (flag. isVote = "true "){
Document. getElementById ("jvForm"). action = "admin/HhArticleVoteCommit. do ";
Document. getElementById ("jvForm"). submit ();
} Else {
Alert ("You have voted! ");
}
});

The action configuration in struts. xml is as follows:
Copy codeThe Code is as follows:
<Action name = "HhCheckVote" method = "checkVote"
Class = "org. bkgd. ehome. jeeplugin. userapp. web. action. ActionHhArticleQuery">
<Result type = "json"> </result>
</Action>

Action
Copy codeThe Code is as follows:
Private String isVote;
Public String getIsVote (){
Return isVote;
}
Public void setIsVote (String isVote ){
This. isVote = isVote;
}
Public String checkVote (){
Try {
List <Map <String, Object> list = aloneIMP. checkVote (ids, getCurrentUser (). search (). getResultList ();
If (list. size () = 0 ){
IsVote = "true ";
} Else {
IsVote = "false ";
}
} Catch (SQLException e ){
// TODO Auto-generated catch block
E. printStackTrace ();
}
Return SUCCESS;
}

PS:
The return value of the action method must be a global variable and must have get, set, or local variables.
The method has a return value. It cannot be void.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.