Jquery.post Usage Sample Code _jquery

Source: Internet
Author: User
Use Ajax to verify that an action is performed on the front end
Jquery.post parameter is
Url,[data],[callback],[type]

URL: Sends the request address.

Data: Key/value parameter to be sent.

Callback: callback function when sending success.

Type: Returns the content format, XML, HTML, script, JSON, text, _default.
Copy Code code 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've already voted!") ");
}
});

The action in Struts.xml is configured as:
Copy Code code as follows:

<action name= "Hhcheckvote" method= "Checkvote"
class= "Org.bkgd.ehome.jeeplugin.userapp.web.action.ActionHhArticleQuery" >
<result type= "JSON" ></result>
</action>

Action
Copy Code code 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 needs to be a global variable and must have a Get,set method, and the local variable is not
Method has a return value and 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.