[問題] ajaxupload,起始物件的問題
大家好,我今天選用http://valums.com/ajax-upload/
這個jquery的套件來上傳檔案
不過在設定上遇到一些問題
以下是我的code
<button class=button id="buttonfile1">上傳圖片1</button>
<button class=button id="buttonfile2">上傳圖片1</button>
<button class=button id="buttonfile3">上傳圖片1</button>
<button class=button id="buttonfile4">上傳圖片1</button>
for(i=1;i<=4;i++)
{ newfile(i);
}
function newfile(file_id)
{
var button = $('#buttonfile'+file_id), interval;
new AjaxUpload(button,{
action:
"/SiteAdmin/update/update_company_image/award.html?lang=en&pic=award"+file_id,
name: 'myfile',
onSubmit : function(file, ext){
if (ext && /^(jpg|jpeg)$/.test(ext)){
button.text('上傳中..');
this.disable();
interval = window.setInterval(function(){
var text = button.text();
if (text.length < 8){
button.text(text + '.');
} else {
button.text('上傳中..');
}
}, 200);
}
else
{
alert("限傳jpg檔!!");
return false;
}
},
onComplete: function(file, response){
button.text('上傳圖片'+file_id);
window.clearInterval(interval);
this.enable();
if(response!='success')
alert(response);
else
{
$('#PImage'+file_id).attr("src", function() {
return
"/.DatawareHouse/.Temp/award/award"+file_id+".jpg?ts="+new Date().getTime();
});
alert('圖片'+file_id+'傳送成功');
}
}
});
}
主要是想要讓interval和button兩個變數名稱不要重複,這樣同時上傳才不會有問題
已試過把變數用陣列或是eval來代入,不過都會有error
請問一下正確的寫法應該要怎麼做比較好呢??感謝!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.194.162.170
推
09/10 12:46, , 1F
09/10 12:46, 1F
→
09/18 18:05, , 2F
09/18 18:05, 2F
→
09/18 18:22, , 3F
09/18 18:22, 3F
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章