This article mainly introduces how the ajaxFileUpload. js plug-in supports Multifile upload. If you need it, refer to the following prerequisites:
Multi-File Upload using the ajaxFileUpload. js plug-in
Steps:
1. Modify the source code (the source code only supports uploading a single file ):
The Code is as follows:
// Pre-modification code -------
// Var oldElement = jQuery ('#' + fileElementId );
// Var newElement = jQuery (oldElement). clone ();
// JQuery (oldElement). attr ('id', fileId );
// JQuery (oldElement). before (newElement );
// JQuery (oldElement). appendTo (form );
// Pre-modification code -------
// Modified code -------
For (var I in fileElementId ){
Var oldElement = jQuery ('#' + fileElementId [I]);
Var newElement = jQuery (oldElement). clone ();
JQuery (oldElement). attr ('id', fileId );
JQuery (oldElement). before (newElement );
JQuery (oldElement). appendTo (form );
}
// Modified code -------
2. Usage:
The Code is as follows:
$. AjaxFileUpload ({
Url: "./upload. action ",
Secureuri: false,
// FileElementId: 'uploadfile1', // original usage
FileElementId: ['uploadfile1', 'uploadfile2', 'uploadfile3', 'uploadfile4', 'uploadfile5'], // usage
DataType: 'json ',
Success: function (data ){
AjaxLoadEnd ();
If (data. result = "success "){
$. Messager. alert ('info', 'import successful. ', 'Info ');
} Else {
$ ('# Import_right'). dialog ('open ');
$. Messager. alert ('info', 'import failed.
Error message: '+ data. message, 'error ');
}
},
Error: function (data, status, e)
{
AjaxLoadEnd ();
$. Messager. alert ('info', 'import failed.
Error message: network exception or form data error. ', 'Error ');
}
});