Home Web Front-end JS Tutorial Related issues such as parameter submission not updating during ajax upload_Basic knowledge

Related issues such as parameter submission not updating during ajax upload_Basic knowledge

May 16, 2016 pm 05:46 PM

Previously, 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:

Copy code The code is as follows:

<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!
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article

Hot Article

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Replace String Characters in JavaScript Replace String Characters in JavaScript Mar 11, 2025 am 12:07 AM

Replace String Characters in JavaScript

jQuery Check if Date is Valid jQuery Check if Date is Valid Mar 01, 2025 am 08:51 AM

jQuery Check if Date is Valid

jQuery get element padding/margin jQuery get element padding/margin Mar 01, 2025 am 08:53 AM

jQuery get element padding/margin

Top 5 Date Manipulation JS Plugins Top 5 Date Manipulation JS Plugins Feb 28, 2025 am 12:34 AM

Top 5 Date Manipulation JS Plugins

10 Worth Checking Out jQuery Plugins 10 Worth Checking Out jQuery Plugins Mar 01, 2025 am 01:29 AM

10 Worth Checking Out jQuery Plugins

10 jQuery Accordions Tabs 10 jQuery Accordions Tabs Mar 01, 2025 am 01:34 AM

10 jQuery Accordions Tabs

jquery add scrollbar to div jquery add scrollbar to div Mar 01, 2025 am 01:30 AM

jquery add scrollbar to div

HTTP Debugging with Node and http-console HTTP Debugging with Node and http-console Mar 01, 2025 am 01:37 AM

HTTP Debugging with Node and http-console

See all articles