Ajaxform refreshing upload

Source: Internet
Author: User
/*************************************** **************************************** ** Ajax submit form *********************************** **************************************** * *** // call example, no way to understand $ (function () {var temphtml = '<input type = "text" id = "AAA" value/> <input name = "file1" type = "file"/>' + "<input type = \ "button \" onclick = \ "ajaxsub \" value = \ "Update \"> "+ '<Div id =" output2 "> </div> '; createform (' Asdfe ', 'dddd', temphtml, 'checkddd ()'); initparam ("/ajaxmodel/default/upload"); createform ('asdfe1', 'aaaaaaaaaaa', temphtml, ''); initparam ("/ajaxmodel/default/upload ") ;}) function checkddd () {var ddasd =$ (" # AAA "). val (); If (ddasd) {return true;} else {alert ('fill in '); Return false ;}} * // ** <Div id = "output2"> </div> * <form method = "Post" id = "educationalform" name = "educationalform"> <input type = "file" class = "F Ileimg "id =" educational "name =" educational "Title =" please upload your diploma "default = 'uploadimg 'onchange =" javascript: checkpic (this) "/> </form> <input type =" hidden "id =" educationalhi "name =" educationalhi "/> ** <SCRIPT> $ (function () {initparamform ("<{$ base_url}> ajaxmodel/default/upload", "educationalform"); initparamform ("<{$ base_url}> ajaxmodel/default/upload ", "stationform"); initparamform ("<{$ base_url}> ajaxmode L/default/upload "," physicianform "); initparamform (" <{$ base_url}> ajaxmodel/default/upload "," professionalform "); initparamform ("<{$ base_url}> ajaxmodel/default/upload", "identificationform");}) function checkpic (OBJ) {var formid = obj. name + "form"; var hid = obj. name + "hi"; fileobj = OBJ; ajaxsub (formid, "") ;}</SCRIPT> ** // var fileobj = NULL, object of the file control; // dynamically created formidvar yuanpengform = ""; // The image ID returned after the upload is successful is hidden Idvar ypimghhid = "";/***** initialization parameter ** suburl submitted action, image ID to be returned **/function initparam (suburl, imghidden) {ypimghhid = imghidden; var Options = {target: '# output2', beforesubmit: showrequest, URL: suburl, success: showresponse}; $ ('#' + yuanpengform ). submit (function () {$ (this ). ajaxsubmit (options); Return false; // block form submission});}/*** initialize the parameter to manually create the form ** suburl submitted action, from ID, ID of the image to be returned **/function I Nitparamform (suburl, formid) {var Options = {target: '# output2', beforesubmit: showrequest, URL: suburl, success: showresponse}; $ ('#' + formid ). submit (function () {$ (this ). ajaxsubmit (options); Return false; // block form submission});}/***** submit form **/function ajaxsub (formid, method) {var flag = true; if (method! = '') {If (! Eval (method) {flag = false ;}} if (FLAG) {$ ('#' + formid ). submit () ;}/ ***** the callback function calls the form data of this method in Ajax requests, jqform jquery form object, options initialization parameter **/function showrequest (formdata, jqform, options) {waitting (); var querystring = $. param (formdata); Return true;}/***** callback function after Ajax is submitted successfully, call ** responsetext to return the output result, whether statustext is successfully executed **/function showresponse (responsetext, statustext, xhr) {removeall (); If (showerror (Er Ror) {var error = $ ("# uploaderror" ).html (); If (error = "no") {alert ("Upload Failed, the image size or type you selected does not meet the requirements! "); Cleanfile (fileobj. name); var objhidden = $ ("input [name = '" + fileobj. name + "Hi']"); objhidden. val ("");} else {// alert ("congratulations, upload successful! "); Var objhidden = $ (" input [name = '"+ fileobj. name + "Hi']"); objhidden. val (error) ;}} function showerror (error) {return true;} function checkpicresponse (responsetext, statustext, xhr) {try {var error = $ ("# uploaderror" ).html (); var jsonss = jquery. parsejson (error); var flag = true; var filename = ""; if (jsonss! = NULL) {for (VAR I = 0; I <jsonss. length; I ++) {If (jsonss [I] [1]! = 1) {flag = false; filename = jsonss [I] [0]; break ;}} else {flag = false;} If (! Flag) {If (filename = "") {filename = fileobj. name;} var OBJ = $ ("input [name = '" + filename + "']"); obj. val (""); alert ("Upload Failed. The image size or type you selected does not meet the requirements! ");} Else {alert (" congratulations, upload successful! "); $ (" # "+ Ypimghhid). Val (error) ;}} catch (e) {alert (" Upload Failed. Please try again later! ") ;}}/***** Dynamically create a form target to specify where to add the form, formid Form ID, and varhtml custom form elements, method calls the method of external injection **/function createform (target, formid, varhtml, method) {yuanpengform = formid; varhtml = varhtml. replace ("ajaxsub", "ajaxsub ('" + yuanpengform + "', '" + method + "')"); vaR temphtml = '<form method = "Post" name = "' + yuanpengform + '" id = "' + yuanpengform + '">' + varhtml + '</form>'; $ ("#" + targetapps.html (temphtml) ;} Function cleanfile (ID) {VaR _ file = document. getelementbyid (ID); If (_ file. files) {_ file. value = "";} else {If (typeof _ file! = "Object") {return NULL;} VaR _ span = document. createelement ("span"); _ span. id = "_ TT _"; _ file. parentnode. insertbefore (_ span, _ file); var TF = document. createelement ("form"); TF. appendchild (_ file); document. getelementsbytagname ("body") [0]. appendchild (TF); TF. reset (); _ span. parentnode. insertbefore (_ file, _ span); _ span. parentnode. removechild (_ span); _ span = NULL; TF. parentnode. removechild (TF) ;}} function ajaxupload (OBJ) {var formid = obj. name + "form"; var hid = obj. name + "hi"; fileobj = OBJ; ajaxsub (formid, "");} function waitting () {if ($ ("# waitifrmaer "). length> 0) {$ ("# waitifrmaer "). eq (0 ). remove (); $ ("# waiter "). eq (0 ). remove (); $ ("# waitimager "). eq (0 ). remove ()} // register divvar waitdiv = document. createelement ("Div"); waitdiv. setattribute ("ID", "waiter"); // register imgvar waitimg = document. createelement ("IMG"); waitimg. setattribute ("src", scripts_url + "scripts/img/upload/waiter123.gif"); waitimg. setattribute ("ID", "waitimager"); // register ifrmaevar waitifrmae = document. createelement ("iframe"); waitifrmae. setattribute ("ID", "waitifrmaer"); waitifrmae. setattribute ("frameborder", "0"); // the content of the document to the page. body. appendchild (waitifrmae); document. body. appendchild (waitdiv); waitdiv. appendchild (waitimg); // set the style $ ("html" ).css ({"height": "100%"}); $ ("body" ).css ({"height ": "100%"}); $ ("Div # waiter" ).css ({"position": "absolute", "Z-index": "10000", "TOP ": "0", "Left": "0", "width": "100%", "height": document.doc umentelement. scrollheight, "background": "# fff"}); $ ("Div # waiter "). fadeto ("fast", 0.8); $ ("IMG # waitimager" ).css ({"position": "absolute", "TOP": document.doc umentelement. scrolltop + 400, "Left": document.doc umentelement. scrollwidth/2}); $ ("iframe # waitifrmaer" ).css ({"position": "absolute", "Z-index": "9990", "TOP ": "0", "Left": "0", "width": "99%", "height": document.doc umentelement. scrollHeight-30}); // test with unbinding event $ ("IMG # waitimager "). BIND ("click", removeall)} function removeall () {$ ("# waitifrmaer "). eq (0 ). remove (); $ ("# waiter "). eq (0 ). remove (); $ ("# waitimager "). eq (0 ). remove ()}

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.