- var button = $ (' #upload_button '); //Define a button that can upload a file.
- 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
- New Ajaxupload (button,{
- Action: ' ${ctp}/app/assistverify/importshanghairreportaction.shtml ',
- Name: ' shanghaifile ', //This is equivalent to <input type = "File" name = "Shanghaifile"/>
- Onsubmit:function (file, ext) {
- if (FileType = = "Zip")
- {
- if (ext &&/^ (zip|rar) $/.test (ext)) {
- This.setdata ({
- ' info ': ' file type is compressed package ' //This info is temporarily invalid
- });
- } Else {
- Alert (' Non-compressed package type file, please re-transmit ');
- return false;
- }
- }
- Button.text (' Import Shanghai credit ... ');
- if (FileNum = = ' one ') //The number of files uploaded at the same time cannot exceed a single
- this.disable ();
- },
- Oncomplete:function (file, response) { //action after upload completed
- if (response! = "Success")
- alert (response);
- Button.text (' import Shanghai Credit ');
- this.enable ();
- if (response = = "Success");
- Alert ("Import Shanghai Credit Success");
- //With response we can do anything, return the file name, file path and so on we can operate freely!
- }
- });
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