JQuery asynchronously submits forms, HTML submits forms to a new window, or IFrame

Source: Internet
Author: User
A tool class. It is said that the JQuery framework implements asynchronous form submission and adds the method [java] // defines the function namespace KevinnewObject () to submit form data to a new window and IFrame (); /*** asynchronous submission form */Kevin. submitAjaxFormfunction (formId... syntax is 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 ="
";
BgObj. innerHTML = html;
// Unlock www.2cto.com
BgObj. onclick = function (){
// New screenClass (). unlock (); // unlock after completion
};
};
}
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.