A tool class. It is said that the JQuery framework implements asynchronous form submission and adds a method to submit form data to a new window and IFrame.
[Java]
// Define the function namespace
Kevin = new Object ();
/**
* Asynchronous form submission
*/
Kevin. submitAjaxForm = function (formId, url, succback, isunlock ){
JQuery. ajax ({
Url: url, // submitted page
Data: $ ("#" + formId). serialize (), // obtain data from the form
Type: "POST", // set the request type to "POST". The default value is "GET"
DataType: "json ",
ContentType: "application/x-www-form-urlencoded; charset = UTF-8", // you must set it to a UTF-8, otherwise commit data garbled
BeforeSend: function (){
If (! Isunlock ){
New screenClass (). lock ();
}
},
Error: function (msg) {// An error occurred while setting the form submission
New screenClass (). unlock ();
Alert ("execution error:" + msg. responseText );
},
Success: function (resp ){
If (! Isunlock ){
New screenClass (). unlock (); // sets how to use form submission
}
If (resp. success = false ){
Alert ("execution failed:" + resp. resultMsg );
} Else if (resp. success = true ){
If (succback = ''| typeof (succback) =" undefined "){
Window. location. href = "success. jsp ";
} Else {
Succback (resp. attributes );
}
} Else {
Alert ("unknown Result:" + resp );
}
},
Cache: false
});
}
/**
* Submit the form to a new window.
*/
Kevin. submitToWindow = function (form, title, url, width, height ){
Var title = title? Title: Math. floor (Math. random () * (1000 + 1 ));
Var winObj = window. open ("", title, "toolbar = no, menubar = no, scrollbars = yes, resizable = no, location = no, status = no ");
Var ie = navigator. userAgent. toLowerCase ();
Ie = ie. match (/msie ([\ d.] + )/)
If (! Ie ){
Alert ('use IE kernel browser ');
} Else {
WinObj. resizeTo (width, height );
}
Var bakTarget = form.tar get;
Var bakAction = form. action;
Form. action = url;
Form.tar get = title;
Form. submit ();
Form.tar get = bakTarget;
Form. action = bakAction;
Return winObj;
}
/**
* Submit the form to the framework.
*/
Kevin. submitToIFrame = function (form, target, url ){
If (target ){
Var bakTarget = form.tar get;
Var bakAction = form. action;
Form. action = url;
Form.tar get = target;
Form. submit ();
Form.tar get = bakTarget;
Form. action = bakAction;
} Else {
Alert ('iframe id cannot be blank ');
}
}
/**
* Screen Processing
*/
Var screenClass = function (){
/// Unlock
This. unlock = function (){
Var divLock = document. getElementById ("divLock ");
If (divLock = null) return;
Document. body. removeChild (divLock );
};
/// Screen lock
This. lock = function (slow ){
Var sWidth, sHeight;
Var imgPath = slow? "Img/waiting_slow.gif": "img/waiting_fast.gif ";
SWidth = document. body. clientWidth;
SHeight = document. body. clientHeight;
Var bgObj = document. createElement ("div ");
BgObj. setAttribute ("id", "divLock ");
BgObj. style. position = "absolute ";
BgObj. style. top = "0 ";
BgObj. style. background = "# cccccc ";
BgObj. style. filter = "progid: DXImageTransform. Microsoft. Alpha (style = 3, opacity = 25, finishOpacity = 75 ";
BgObj. style. opacity = "0.6 ";
BgObj. style. left = "0 ";
BgObj. style. width = sWidth + "px ";
BgObj. style. height = sHeight + "px ";
BgObj. style. zIndex = "100 ";
Document. body. appendChild (bgObj );
Var html = "<table border = \" 0 \ "width = \" "+ sWidth +" \ "height = \" "+ sHeight +" \ "> <tr> <td valign = \ "middle \" align = \ "center \"> <image src = \ "" + imgPath + "\"> </td> </tr> </ table> ";
BgObj. innerHTML = html;
// Unlock www.2cto.com
BgObj. onclick = function (){
// New screenClass (). unlock (); // unlock after completion
};
};
}