Previously, I downloaded a jquery ajax upload plugin from the internet, the left side of the page is the upload category, want to implement a function is so: I originally intended to be in the server according to the upload classification to create a different folder to save the file, so this needs to pass a upload classification parameters to the background. These upload classifications are read from the database and generated using repeater. When you click on one of the categories, set a style for him and save the name of the category in a variable uploadcatlog. I can get the classification and pass it to the background, but it's strange that only the first time is correct, and every parameter will not be updated. In fact, in the upload plug-in OnComplete callback function also used in the Uploadcatlog, its value has been updated. I feel like this upload plugin only in the first click of the time to instantiate and pass parameters to the background, so the value is unchanged, how should we solve this problem? Here is the details of my JS code:
JavaScript Code:
Copy Code code as follows:
<script type= "Text/javascript" >
$ (function () {
var Uploadcatlog;
Set the current selection style for the master page navigation bar
$ ("#menu. Nav5"). AddClass ("Menu_active"). Siblings (). Removeclass ("menu_active");
Generate category menu styles and navigation menus
$ ("#kllst li"). Click (function () {
$ (this). addclass ("Currentli"). Siblings (). Removeclass ();
Uploadcatlog = $ (this). text ();
});
var btnupload = $ (' #upload ');
var status = $ (' #status ');
Btnupload.click (function () {
if (Uploadcatlog = = undefined) {
Status.text ("You must first select the category of uploaded files!") "). AddClass (' error ');
return false;
}
New Ajaxupload (Btnupload, {
Action: ' Handler/doupload.ashx ',
Name: ' UploadFile ',
Onsubmit:function (file, ext) {
if (!) ( Ext &&/^ (Doc|docx|xls) $/.test (EXT))) {
Status.text (' only support word,excel format upload! '). addclass (' error ');
return false;
}
Status.text (' Uploading, please wait ... ');
},
Data: {"Catlog": Uploadcatlog},
Oncomplete:function (file, response) {
Status.text ('). Removeclass (' error ');
if (response = = "Success") {
var Fimgtype;
if (File.indexof (". Doc")!=-1 | | | file.indexof (". docx")!=-1) {
Fimgtype = "word";
}
if (File.indexof (". xls")!=-1) {
Fimgtype = "Excel";
}
$ (' <li></li> '). Appendto (' #files '). html (' <br/> [' + Uploadcatlog + '] ' + file '. AddClass (' success ');
} else {
$ (' <li></li> '). Appendto (' #files '). Text (file). addclass (' error ');
}
}
});
});
});
</script>
Then a solution was found: the instance is not changed after it is created, and the SetData method can be invoked in the onsubmit callback function to set the dynamic parameters, such as the following code and comment details:
JavaScript Code:
You can use these methods to configure an AJAX upload
var upload = new Ajaxupload (' #div_id ', {action: ' upload.php '});
For example, when the user chooses something, set some parameters
Upload.setdata ({"Catlog":
Ajax upload parameter submission, always because of a variety of errors and problems, but how to solve the problem, how to use the best way to solve the problem, is worth digging into the problem, to be a good solution to the problems in the programming process, or need to continue their research and study!