亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

ajax實現異步上傳圖片的方法

ajax實現異步上傳圖片的方法

PHP
陳家二公子 2016-02-21 12:38:51
怎么實現異步多圖上傳? ?并將路徑上傳到數據庫呢? ? ?我是講多圖保存到session中的數組中先,然后在提交! ?但是總感覺這樣做事錯誤的,真正實現是怎么做的呢?
查看完整描述

1 回答

?
wanka

TA貢獻10條經驗 獲得超10個贊

$("#file?input[type=file]").on("change",?function(event){
????var?files?=?event.target.files;
????var?data?=?new?FormData();
????$.each(files,?function(key,?value)
????{
????????data.append("file",?value);
????});
????$.ajax({
????????url:?"",
????????type:?"POST",
????????data:?data,
????????async:?true,
????????cache:?false,
????????dataType:?"json",
????????processData:?false,
????????contentType:?false,
????????success:?function(){
????????????if(data.error_code?===?0){
????????????????$('#icon').removeClass('hidden');
????????????????$('#icon?input').val(data.url);
????????????????$('#icon?img').attr('src',?data.url);
????????????????$("#file").addClass("hidden");
????????????????$("#file?input[type=file]").val("");
????????????}else{
????????????????$("#file?input[type=file]").val("");
????????????????var?errorMsg?=?data.error_msg?||?"圖片上傳失敗,請重試!";
????????????????alert(errorMsg);
????????????}
????????},
????????error:?function(data,jqXHR,?textStatus,?errorThrown){
????????????alert(JSON.parse(data.responseText).error_msg);
????????}
????});
});


查看完整回答
5 反對 回復 2016-02-23
  • 1 回答
  • 10 關注
  • 2410 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號