1, file upload, picture upload, Third-party uploadify plug-ins, http://www.uploadify.com/about/
2, the use of IFrame upload files, submit the form, the main idea is:
A, JS create form form, IFRAME, add to the body, form target and the name of the IFrame consistent.
B, Form form to update the data, submit submission
C, if uploaded files, pictures, form inside add input-file elements, Binding onchange event, JS Trigger, add submit event inside OnChange
D, on the callback: After the success of the IFRAME submission, the returned data in the IFRAME inside the page, you can get this, you need to split:
$iframe [0].contentwindow.document.queryselector (' body '). InnerHTML
Code slices:
var target = ' framefile '; var input = ' <input type= "file" name= "file" onchange= "Changeimage ()" > ' + ' <input name= "appId" value= "' +id+ '"
; ' + ' <input type= "submit" name= "submit" value= "submit" > "; var $form = $ (' <form action= ' + URL + ' "target=" ' + Target + ' "enctype=" Multipart/form-data "method=" post "id=" Upimagefo
RM "style=" Display:none "> ' +input+ ' </form>"). Appendto (' body ');
var $iframe = $ (' <iframe name= ' + target + ' "style=" Display:none "></iframe>"). Appendto (' body ');
$form. Find (' input ')-eq (0). Click ();
Window.changeimage = function () {$form. Find (' input '). EQ ( -1). click ();}; Detects the IFRAME page load $iframe. Load (function (e) {var str = $iframe [0].contentwindow.document.queryselector (' body ').
InnerHTML;
var data = SPT (str);
$form. Remove ();
$iframe. Remove ();
callback (data);
});
function SPT (str) {//string is split into object var a = Str.indexof (' {');
var B = str.indexof ('} ');
var j = {};
var t = [];
var s = str.substring (a+1,b); s = s.replace (/"/gi,'');
t = S.split (', ');
for (var i=0 i<t.length; i++) {var tmp = T[i].split (': ');
J[tmp[0]] = tmp[1];
};
Return J; };
2-c correction, the above code has bugs:
Manually triggering the Input-file onchange event and submit it in the event is problematic. Because the onchange event is triggered, the selection begins and the submit is submitted.
Upload function, form form elements can only be placed in HTML.
The above file upload, iframe cross-domain data submission is small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.