ajax上传时参数提交的问题

yaotomo 2012-12-05 02:29:58
我是下载的一个jQuery的Ajax上传插件。网页左侧是上传分类,我打算在服务端根据上传分类建立不同的文件夹来保存文件,所以要传一个上传分类参数给后台。这些上传分类是从数据库读出,用repeater生成的。当点击其中一个分类时就给他设置一个样式,并且将这个分类的名字保存到一个变量uploadCatlog中。我可以取到分类并传给后台,但是只有第一次是正确的,以后的每次参数都不更新。其实在上传插件的onComplete回调函数中也用到了uploadCatlog,他的值已经更新了。我觉得好像这个上传插件只在第一次点击的时候实例化并将参数传给后台,所以以后值都是不变的。。应该怎么解决这个问题呢?求大神指点。。


<script type="text/javascript">
$(function () {
var uploadCatlog;

//设置母版页导航栏的当前选中样式
$("#menu .nav5").addClass("menu_active").siblings().removeClass("menu_active");
//生成类别菜单样式和导航菜单
$("#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("必须先选择上传文件的类别!").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('只支持WORD,EXCEL格式上传!').addClass('error');
return false;
}
status.text('正在上传,请稍候...');
},
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>
...全文
146 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
yaotomo 2012-12-05
  • 打赏
  • 举报
回复
谢谢高手,解决了。
Go 旅城通票 2012-12-05
  • 打赏
  • 举报
回复
创建实例后就不会变了,可以在onSubmit回调函数中调用SetData方法设置动态参数
//您可以使用这些方法来配置AJAX的上传
var upload = new AjaxUpload(‘#div_id’,{action: ‘upload.php’});
//例如当用户选择了一些东西,设置一些参数
upload.setData({ "catlog": uploadCatlog });

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧