About jQuery's real case record for retrieving JSON data returned by Action

Source: Internet
Author: User

The page code and Action Code are listed here for reference:

 

Page code (jQuery ajax asynchronous request for data ):

 

[Javascript]
<Span style = "font-family: Microsoft YaHei; font-size: 13px;"> // save decision information
Function savedemo (){
Var rowid = checkSelected ();
Var rowData = jQuery ("# list"). jqGrid ('getrowdata ',
Rowid );
Var processIsRight = rowData ["processIsRight"];
If (rowid =-1) {alert ("only one recommended solution can be selected"); return ;}
Else if (processIsRight = 0) {// check whether the process is faulty
Alert ("there are no default persons for tasks under this process scheme, please carefully check this process scheme"); return;
}
// Determine whether the decision maker is selected: Required
Var _ decisionMaker = $ ("# businessModule"). find ("option: selected"). val ();
If (_ decisionMaker = ''| _ decisionMaker =" undefined ") {alert (" select a decision maker! "); Return ;}
Else if (rowid> 0 ){
Var url = "savedemo-. action? "+ GetParams ();
// Document. write (url );
Alert (url );
/***/
$. Ajax ({
Url: url,
Type: 'post ',
DataType: 'json ',
Success: function (json ){
// Reference: http://blog.csdn.net/jpr1990/article/details/6931027
Alert (json );
Window. close ();
},
Error: function (){
Alert ('data loading failed, please try again ..');
// Window. close ();
}
});

} Else {
Alert ("select a recommended solution"); return;
}
} </Span>

Code related to the background Action class (mainly to see how to return JSON data ):

[Java]
<Span style = "font-family: Microsoft YaHei; font-size: 13px;"> /**
* Save decision information
*
0-not started.
1-pause.
2-running.
3-failed.
4-termination.
5-complete.
6-deleted.
*/
Public String save (){
If (includemo! = Null ){
Try {
// Generate the actual decision time
Timestamp decision_date = new Timestamp (System. currentTimeMillis (); // It cannot be later than the force decision time and no judgment has been made

Includemo-. setDecisionMaker (includemo-. getDecisionMaker ());

Includecision. setDecisionTime (decision_date );
// Determine whether the process is automatically started
If (this. getIsStartProcess (). equals ("true ")){
Includemo-. setSolutionState (2); // set SolutionState to: 2-running
This. decisionExecutorService. saveassistdemo-( includemo-, true, processId, emgencyInfoProcessId );
} Else {
Includemo-. setSolutionState (0); // set SolutionState to: 0-not started
This. decisionExecutorService. saveassistdemo-( includemo-, false, processId, emgencyInfoProcessId );
}
JsonMassage = "decision successful, data saved! ";
} Catch (Exception e ){
E. printStackTrace ();
JsonMassage = "there are no default jobs under this process scheme. Please carefully check this process scheme ";
System. out. println (jsonMassage );
Return SUCCESS;
}
}
Return SUCCESS;
 
} </Span>
 

Directly print System. out. println (jsonMassage); then return SUCCESS; then jsonMassage data can be returned to the success method on the page:

[Javascript]
<Span style = "font-family: Microsoft YaHei; font-size: 13px;"> success: function (json ){
// Reference: http://blog.csdn.net/jpr1990/article/details/6931027
Alert (json );
Window. close ();
},
Error: function (){
Alert ('data loading failed, please try again ..');
// Window. close ();
}
</Span>

From Hurry's column

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.