


Related issues such as parameter submission not updating during ajax upload_Basic knowledge
May 16, 2016 pm 05:46 PMPreviously, I downloaded a jQuery Ajax upload plug-in from the Internet. The left side of the web page is the upload category. The function I want to implement is as follows: I originally planned to create different folders based on the upload category on the server side to save it. file, so this requires passing an upload classification parameter to the background. These upload categories are read from the database and generated using repeater. When one of the categories is clicked, a style is set for it, and the name of the category is saved in a variable uploadCatlog. I can get the classification and pass it to the backend, but the strange thing is that it is correct only the first time, and the parameters are not updated every time thereafter. In fact, uploadCatlog is also used in the onComplete callback function of the upload plug-in, and its value has been updated. I feel like this upload plug-in is only instantiated when clicked for the first time and the parameters are passed to the background, so the values will remain unchanged in the future. How should I solve this problem? The following are the details of my js code:
JavaScript code:
<script type="text/javascript">
$(function () {
var uploadCatlog;
//Set the currently selected style of the master page navigation bar
$(" #menu .nav5").addClass("menu_active").siblings().removeClass("menu_active");
//Generate category menu style and navigation menu
$("#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 the uploaded file!").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 supports WORD, EXCEL format upload!').addClass('error');
return false;
}
status.text('In progress Upload, 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('<img src="images/' fimgtype '. png" alt="" /><br />[' uploadCatlog ']' file).addClass('success');
} else {
$('<li></ li>').appendTo('#files').text(file).addClass('error');
}
}
});
});
}) ;
</script>
Later I found a solution, that is: after creating the instance, it will not change. You can call the SetData method in the onSubmit callback function to set dynamic parameters. The following code and comment details:
JavaScript code:
//You can use these methods to configure AJAX upload
var upload = new AjaxUpload('#div_id',{action: 'upload.php'} );
//For example, when the user selects something and sets some parameters
upload.setData({ ”catlog”:
Ajax upload parameters are always submitted due to various errors. A problem occurs, but how to solve the problem and how to use the best method to solve the problem is a problem worthy of further study. If you want to solve the problems that arise during the programming process, you still need to continue to study and learn!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Replace String Characters in JavaScript

HTTP Debugging with Node and http-console
