Dwz framework --- (2) form callback function

Source: Internet
Author: User

The form callback functions in dwz include:

/*** Submit a common Ajax form * @ Param {object} callback * @ Param {string} confirmmsg prompting for confirmation */function validatecallback (form, callback, confirmmsg) {var $ form = $ (form); If (! $ Form. valid () {return false;} VaR _ submitfn = function () {$. ajax ({type: form. method | 'post', URL: $ form. ATTR ("action"), data: $ form. serializearray (), datatype: "JSON", cache: false, success: callback | dwz. ajaxdone, error: dwz. ajaxerror});} If (confirmmsg) {alertmsg. confirm (confirmmsg, {okcall: _ submitfn});} else {_ submitfn ();} return false ;}
/*** Submit an Ajax form with File Upload * @ Param {object} form * @ Param {object} callback */function iframecallback (Form, callback) {var $ form = $ (form), $ IFRAME = $ ("# callbackframe"); If (! $ Form. valid () {return false;} if ($ IFRAME. size () = 0) {$ IFRAME = $ ("<IFRAME id = 'callbackframework' name = 'callbackframework' src = 'about: blank 'style = 'display: none '> </iframe> "). appendto ("body");} If (! Form. ajax) {$ form. append ('<input type = "hidden" name = "ajax" value = "1"/> 'specify parameter form.tar get = "callbackframe"; _ iframeresponse ($ IFRAME [0], callback | dwz. ajaxdone);} function _ iframeresponse (IFRAME, callback) {var $ IFRAME = $ (IFRAME), $ document = $ (document); $ document. trigger ("ajaxstart"); $ IFRAME. BIND ("LOAD", function (event) {$ IFRAME. unbind ("LOAD"); $ document. trigger ("ajaxstop"); If (IFRAME. src = "expose crip T: '% 3 chtml % 3E % 3C/html % 3E'; "| // For safariiframe. src = "javascript: '<HTML> 


The previous two examples are as follows:

Form is generally replaced by this. Callback refers to the callback function, which can be customized. Write a callback (JSON) method in JS and call it during callback. confirmmsg displays the prompt information.

The following is an example of iframecallback (Form, callback) with file upload:

<Form ID = "canshuwwwwww" method = "Post" Action = "<% = basepath %>/SDSC/job/jobparamcreate" enctype = "multipart/form-Data" class =" pageform required-validate "onsubmit =" Return iframecallback (this, callback); "> <! -- Onsubmit = "Return iframecallback (this);" Return validatecallback (this, ajaxdone2); --> <Table Style = "line-Height: 20px; margin-left: 20px; "> <! -- Input disables input --> <tr> <TD> <label> select a parameter: </label> <input id = "softparamid" name = "softwareparam. ID "value =" "type =" hidden "/> <TD> <input id =" softname "class =" required "name =" softwareparam. name "type =" text "readonly =" readonly "style =" width: 220px; "Disabled =" disabled "/> <TD> <strong> <a id =" find "href =" "style =" float: left; "Class =" btnlook "lookupgroup =" softwareparam "Title =" select the software parameter "width =" 400 "> search back </a> </strong> <tr> <TD> <label> parameter value: </label> <TD> <input id = "paramvalue" type = "text" name = "paramvalue" class = "required" size = "20" maxlength = "32" Style = "width: 220px; "Disabled =" disabled "/> <tr> <TD> <label> file: </label> <TD> <input id = "uploadfile" name = "uploadfile" type = "file"/> <input id = "softwareid" name = "softwareid" value = "" type = "hidden"/> <input id = "jobinfoid" name = "jobinfoid" value = "" type = "hidden"/> <TD> <Div class =" buttonactive "> <Div class =" buttoncontent "> <button type =" Submit "> OK </button> </div> </table> </form>


 

Function callback (JSON) {// alert (JSON. ID); // callback function for submitting parameters // Add a row in the table newrow = document. all. yltable. insertrow (-1); J_1 ++; newrow. id = JSON. ID; Newcell = newrow. insertcell (); Newcell. classname = "cell"; // newrow. bgcolor = '# ffff'; Newcell. align = 'center'; // Newcell. innerhtml = ""; Newcell. innerhtml = "row" + J_1 + "; Newcell = newrow. insertcell (); // newrow. bgcolor = '# ffff'; Newcell. classname = "cell"; Newcell. align = 'center'; Newcell. in Nerhtml = JSON. paramname; Newcell = newrow. insertcell (); // newrow. bgcolor = '# ffff'; Newcell. classname = "cell"; Newcell. align = 'center'; // alert (document. getelementbyid ("AAAAA") // Newcell. innerhtml = '<input name = "button3" type = "button" onclick = "delrow1 () "value =" delete 1 "> <input name =" button3 "type =" button "onclick =" delrow2 () "value =" Delete 2 "> '; Newcell. innerhtml = JSON. paramvalue; Newcell = newrow. insertcell (); // newro W. bgcolor = '# ffff'; Newcell. classname = "cell"; Newcell. align = 'center'; // Newcell. innerhtml = '<Shiro: haspermission name = "dojob: delete "> <a class =" delete "target =" ajaxtodo "href ="/workbench/SDSC/job/jobparamdelete/'+ JSON. ID + '"Title =" are you sure you want to delete this parameter? "> <Span> Delete </span> </a> </Shiro: haspermission> '; Newcell. innerhtml =' <a Title =" are you sure you want to delete this parameter? "Onclick =" Submit ('+ JSON. ID + ') "> <span> Delete </span> </a>'; document. all. yltable. focus ();} function submit (a) {$. ajax ({URL: "/workbench/SDSC/job/jobparamdelete/" + A, data :{}, type: "Post", datatype: 'json', success: function (data) {var table = document. getelementbyid ('ltable'); document. getelementbyid (). parentnode. removechild (document. getelementbyid (A) ;}, error: function () {alert ("failed ");}});}


 

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.