Jquery Ajax File Upload (source code)

Source: Internet
Author: User

Project Structure

Default. aspx
Upload. aspx
Scripts /...
Style.css

Client htmlCode

Hide row number Copy code ? Default. aspx
  1. <%@PageLanguage= "VB"Autoeventwireup= "False"Codebehind= "Uploadfile. aspx. VB"Inherits= "Web. uploadfile"%>
  2. <!DoctypeHTML public"-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <HtmlXmlns= "Http://www.w3.org/1999/xhtml">
  4. <HeadRunat= "Server">
  5. <Title> </Title>
  6. <LinkREL= "Stylesheet"Type= "Text/CSS"Href= "Style.css"Media= "All"/>
  7. <ScriptType= "Text/JavaScript"SRC= "../Scripts/jquery-1.4.1.min.js"> </Script>
  8. <ScriptType= "Text/JavaScript"SRC= "../Scripts/ajaxupload.3.5.js"> </Script>
  9. <ScriptType= "Text/JavaScript">
  10. $ (Function(){
  11. VaRBtnupload = $ ('# Upload');
  12. VaRStatus = $ ('# Status');
  13. NewAjaxupload (btnupload ,{
  14. Action:'Upload. aspx',
  15. // Name of the file input box
  16. Name:'Uploadfile',
  17. Onsubmit:Function(File, ext ){
  18. If(! (Ext &/^ (JPG | PNG | JPEG | GIF) $/. Test (EXT ))){
  19. // Check for valid File Extension
  20. Status. Text ('Only JPG, PNG or GIF files are allowed');
  21. Return false;
  22. }
  23. Status. Text ('Uploading ...');
  24. },
  25. Oncomplete:Function(File, response ){
  26. // On completion clear the status
  27. Status. Text ('');
  28. // Add uploaded file to list
  29. If(Response ="Success"){
  30. $ ('<Li> </LI>'). Appendto ('# Files'Pai.html ('+ File +'"Alt =" "/> <br/>'+ File). addclass ('Success');
  31. }Else{
  32. $ ('<Li> </LI>'). Appendto ('# Files'). Text (file). addclass ('Error');
  33. }
  34. }
  35. });
  36. });
  37. </Script>
  38. </Head>
  39. <Body>
  40. <FormID= "Form1"Runat= "Server">
  41. <DivID= "Upload">
  42. Upload File
  43. </Div>
  44. <! -- Upload button -->
  45. <DivID= "Div1">Upload File</Div> <SpanID= "Status"> </Span>
  46. <! -- List files -->
  47. <UlID= "Files"> </Ul>
  48. </Form>
  49. </Body>
  50. </Html>

Server processing code upload. aspx

Hide row number Copy code ? Default. aspx
  1. UsingSystem;
  2. UsingSystem. Collections. Generic;
  3. UsingSystem. LINQ;
  4. UsingSystem. Web;
  5. UsingSystem. Web. UI;
  6. UsingSystem. Web. UI. webcontrols;
  7. NamespaceJqueryajaxuploadtest
  8. {
  9. Public partial classUpload: System. Web. UI.Page
  10. {
  11. Protected voidPage_load (ObjectSender,EventargsE)
  12. {
  13. Try
  14. {
  15. HttppostedfileHpffile = request. Files ["Uploadfile"];
  16. Hpffile. saveas (server. mappath ("~ /Uploads /") + Hpffile. filename );
  17. Response. Write ("Success");
  18. }
  19. Catch(Exception)
  20. {
  21. Response. Write ("Fail");
  22. }
  23. }
  24. }
  25. }

: Http://pjw100.download.csdn.net/
Find the file jquery Ajax File Upload (the file has just been uploaded and may not be flushed out)

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.