Simple application of jquery plugin Ajaxupload

Source: Internet
Author: User

  1. var button = $ (' #upload_button '); //Define a button that can upload a file.
  2. var fileType = "Zip", FileNum = "one"; //define the types of files that can be uploaded, of course, rely on the onsubmit in the back of the JS to make judgments
  3. New Ajaxupload (button,{
  4. Action: ' ${ctp}/app/assistverify/importshanghairreportaction.shtml ',
  5. Name: ' shanghaifile ', //This is equivalent to <input type = "File" name = "Shanghaifile"/>
  6. Onsubmit:function (file, ext) {
  7. if (FileType = = "Zip")
  8. {
  9. if (ext &&/^ (zip|rar) $/.test (ext)) {
  10. This.setdata ({
  11. ' info ': ' file type is compressed package ' //This info is temporarily invalid
  12. });
  13. } Else {
  14. Alert (' Non-compressed package type file, please re-transmit ');
  15. return false;
  16. }
  17. }
  18. Button.text (' Import Shanghai credit ... ');
  19. if (FileNum = = ' one ') //The number of files uploaded at the same time cannot exceed a single
  20. this.disable ();
  21. },
  22. Oncomplete:function (file, response) { //action after upload completed
  23. if (response! = "Success")
  24. alert (response);
  25. Button.text (' import Shanghai Credit ');
  26. this.enable ();
  27. if (response = = "Success");
  28. Alert ("Import Shanghai Credit Success");
  29. //With response we can do anything, return the file name, file path and so on we can operate freely!
  30. }
  31. });


Of course, this code must rely on JS to run, please add the above code in the code block of ready. Please also introduce ajaxupload.js, see attachment download!

    • Ajaxupload.rar (6.5 KB)
    • Download number of times: 427

Simple application of jquery plugin Ajaxupload

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.