Ajax implementation of child page data to the parent page

Source: Internet
Author: User

1. Parent page:

This list data needs to be brought from the child page, query out for a list, need to be replaced with JSON.

2.js

Initiate verification
function Getinspect () {
var Flowid = $ ("#flowId"). Val ();
var Injureid = $ ("#injureId"). Val ();
var tasktype = $ ("#taskType"). Val ();
var url = path+ "/inspect/dostartinspectflow.do?injureid=" +injureid+ "&tasktypes=" +tasktype+ "&flowId=" + Flowid;
window.open (URL, "", "Dialogwidth=1020px,dialogheight=700px,dialogleft=100px,dialogtop=120px,resizable=yes, Scrollbars=yes ");
}

3.struts

<!--launch Mission-->
<action name= "Dostartinspectflow" class= "cminspectaction" method= "Dostartinspectflow" >
<result>/jsp/inspect/start_inspect.jsp</result>
</action>

4.action

Public String Dostartinspectflow () throws Exception {
Flowid = This.getparameter ("Flowid");
Used to determine the child page Execution parent page JS
String backfull = This.getparameter ("Backfull");
Injureid = This.getparameter ("Injureid");
List List = (list) cmcommonservice.getdictlistbycode ("D202"). Get ("D202");
flows = Cminspectservice.getlistinspectflowdto (Injureid);
/*for (int i = 0; i < list.size (); i++) {//Remove initiated task in task List
Mddictelement e = (mddictelement) list.get (i);
if (flows = null | | flows.size () = 0) {
Tasktypelist = list;
Break
}
Boolean contains = false;
for (int j = 0; J < Flows.size (); j + +) {
Flows.get (j). Setinitiatordate (Flows.get (j). Getinitiatordate (). substring (0, 19));
if (Flows.get (j). Gettasktype (). Equals (E.getdictcode ())) {
contains =!contains;
}
}
if (!contains) {
Tasktypelist.add (e);
}
}*/
Tasktypelist=list;
if (backfull!=null) {
SetAttribute ("Backfull", "backfull");
}
return constant.success;
}

5. Sub-page Save JS

function Save () {
var handlername=$ ("#handlerName"). Val ();
if (handlername.length>0) {
if ($ (": Checked"). Size () > 0) {
var audiname=$ ("#treeorg"). Val ();
$ ("Form:first"). attr ("Action", "<%=path%>/inspect/doaddinspectflow.do?autiname=" +audiname); Execute action

$ ("Form:first"). Submit ();
}else{
Alert ("Please select task type!");
}
}else{
Alert ("Please select the task recipient!");
}
}
<c:if test= "${backfull== ' Backfull '}" >
$ (function () {

Window.parent.opener.document.getElementById ("Backfullval"). value= ' ${injureid} ';
Window.parent.opener.backfull (); The parent page executes the Ajax method
});
</c:if>

6. The parent page executes the Ajax method

Initiate verification-refresh from subpage to parent page
function Backfull () {
var injureid=$ ("#backfullval"). Val ();
$.ajax ({
Type: "POST",
Async:false,
Url:getrootpath () + "/inspect/doloadinspectinform.do?injureid=" +injureid,
Success:function (data) {
var str= ';
$ ("#backfull"). HTML ("");
for (Var i=0;i<data.length;i++) {
var str1= ';
if (data[i].taskstate==1) {
Str1= ' pending verification ';
}else if (data[i].taskstate==2) {
Str1= ' pending review ';
}else if (data[i].taskstate==3) {
Str1= ' audit completed ';
}
str+= ' <tr> ';
str+= ' <td style= ' width:25%; > ';
str+= Data[i].taskname;
str+= ' </td> ';
str+= ' <td style= ' width:25%; > ';
str+= new Date (data[i].initiatordate). Format (' Yyyy-mm-dd hh:mm:ss ');
str+= ' </td> ';
str+= ' <td style= ' width:25%; > ';
str+= str1;
str+= ' </td> ';
str+= ' <td style= ' width:25%; > ';
str+= ' <input type= ' button ' onclick= ' Todetail (\ ' +data[i].id+ ' \ ', \ ' +data[i].injureid+ ' \ ', ' \ ' ', ', \ ') +data[i].tasktype + ' "class=" button "value=" detailed "/>";
str+= ' </td> ';
str+= ' </tr> ';
}
$ ("#backfull"). Append (str);
$ ("#InspectFlowId"). Show ();
if ($ ("#InspectFlowId"). Find (". List-data-show"). Is (": hidden")) {
$ ("#InspectFlowId"). Find (". Title"). Click ();
}
}
});
};

7.ajax Action

public void Doloadinspectinform () throws Exception {
HttpServletRequest request=getrequest ();
String Injureid = Request.getparameter ("Injureid");
List inspectlist = cminspectservice.getlistinspectflowdto (Injureid);
HttpServletResponse response = GetResponse ();
Response.setcontenttype ("Text/json;charset=utf-8");
PrintWriter out = Response.getwriter ();
Out.print (Json.tojsonstring (inspectlist). toString ());
Out.flush ();
Out.close ();
}

8. Additional

JS format time milliseconds-24 hours
Date.prototype.format =function (format) {
var o = {
"m+": This.getmonth () +1,//month
"D+": This.getdate (),//day
"h+": this.gethours (),//hour
"m+": This.getminutes (),//minute
"S+": This.getseconds ()//second
}
if (/(y+)/.test (format))
Format = Format.replace (regexp.$1, (this.getfullyear () + ""). substr (4-regexp.$1.length));
For (var k in O)
if (new RegExp ("+ K +")). Test (format)
Format = Format.replace (regexp.$1, regexp.$1.length = 1? O[k]: ("+ o[k]"). substr (("" + o[k]). length);
return format;
};

9. Sub-page:


Related Article

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.