var asyn = {
formSubmit: function (args, action, func) {
this.clearContext();
var subArr = [ ];
var subArrT = [];
if (b$.type.isArray(args)) {
subArr = args>} else {
var タグ = args.tagName toLowerCase() ;
if (tag == "form") { for (var i = 0, num = args.childNodes.length; i
else { subArr = [args]; }
}
//非同期フォームと ifroma
var objForm = document.createElement("form");アクション = アクション ;
objForm.target = "bBankAsynFormSubmit_iframe_1b";
objForm.method = "post"; ";
objForm.style.display = "none";
var objIframe = b$.parseDom('')[0];
//
のフォームに送信値を追加します(var i = 0, num = subArr.length; i if (!subArr[i].name && subArr[i].nodeType == 1 && subArr[i].tagName. toLowerCase() == "入力") subArr[i].name = "bBankAsynFormSubmit_input_1b_" i;
var input = subArr[i].cloneNode(true);
subArr[i ].parentNode.replaceChild(input, subArr[i]);
objForm.appendChild(subArr[i]);
}
//submit
document.body.appendChild(objIframe) );
document.body.appendChild(objForm);
//dispose
for (var i = 0, num = subArrT.length; i if (func) this.callBack = func;
complete: function () {
var responseText = "";
try {
var objIframe = document.getElementById("bBankAsynFormSubmit_iframe_1b");
if (objIframe.contentWindow) { responseText = objIframe.contentWindow.document.body. innerHTML; }
else {responseText = objIframe.contentDocument.document.body.innerHTML; }
} catch (err) { }
this.clearContext()
if (this.callBack) .callBack(responseText);
},
clearContext: function () {
if (b$('#bBankAsynFormSubmit_form_1b')) b$('#bBankAsynFormSubmit_form_1b').removeSelf(); if (b $('#bBankAsynFormSubmit_iframe_1b')) b$('#bBankAsynFormSubmit_iframe_1b').removeSelf();
},
callBack: null
;
Simple explanation:
In fact, the more troublesome part is dealing with the multi-browser compatibility issue of iframe. In fact, we don’t have to dig into the compatibility issue of iframe. Let’s hand over the compatibility issue. Let the browser parse and solve it by itself. Here we use string conversion to DOM.
First, I created a form and iframe, both of which were hidden. I transferred the content of the form to the hidden form I created, and then submitted the created hidden form. After all is completed, remove the created form and iframe.
Usage:
asyn.formSubmit(args, action [, func]) arg: can be a form form, an input form element, or an array of input form elements. action: submitted url. func: callback function
Example: asyn.formSubmit(inputArr, 'xxx.aspx', function(d){
alert(d);
});
END
That’s it It’s over. Here I recommend a js framework I wrote myself. The above method is integrated into the framework
Use:
b$.asyn.formSubmit(inputArr, 'xxx.aspx', function(d){
alert(d);
} );