Upload series: Ajaxupload.js

Source: Internet
Author: User

Ajaxupload.js

Last time said Jquery.upload.js, this time again ajaxupload.js, this actually also relatively simple answer, only a JS file:

HTML code:

1 $ (function () {2 var btnupload = $ (' #upload ');3 New Ajaxupload (Btnupload, {4 action: '/system/upload ',//upload address5 name: ' UploadFile ',//file name Word6 onsubmit:function (file, ext) {//Pre-upload action7 if (! ( Ext &&/^ (jpg|gif|jpeg|png) $/.test (EXT))) {8 $.messager.alert (' Hint ', ' pro ', please select JPG, PNG, GIF, JPEG pictures! ');9 return false;Ten                 } One var ele = $ (". Imglist li"); A if (ele.length >= 5) { - $.messager.alert (' Hint ', ' pro, upload up to five photos! '); - return false; the                 } -             }, - oncomplete:function (file, response) {//post-upload operation (information returned by the response server) -var html = '<Li><span><imgsrc= "' + response + '"/><P>'; + if ($ (". Imglist"). Find (' li '). Length > 0) { -HTML + = '<inputtype= "Radio"name= "img"value= "' + response + '" />'; + } else { AHTML + = '<inputtype= "Radio"name= "img"value= "' + response + '"checked= "Checked" />'; at                 } -HTML + = '<ahref= "javascript:void (0)"onclick= "defimg (this)">Main diagram</a>|<ahref= "javascript:void (0)"onclick= "delimg (this)">Delete</a>'; -HTML + = '</P></span></Li>'; - $ ('. Imglist '). Append (HTML); -             } -         }); in});
View Code

The background code is similar to Jquery.upload.js, but one thing to note is that this ajaxupload.js in the background to accept files, such as the background method:

1  Public actionresult Upload (httppostedfilebase FileData) 2         {3            4         }
View Code

MVC does not map directly to it, so there are more deceptive where we need to go through the code and get the upload file.

1  Public actionresult Upload (httppostedfilebase FileData) 2         {3             FileData = request.files["uploadfile"]; 4         }
View Code

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.