通過ajax上傳表單檔案

2022-08-11 02:21:21 字數 1778 閱讀 6133

html部分:

<

form

method

="post"

id="productuploadform"

name

="frmbatchsettle"

enctype

="multipart/form-data"

encoding

="multipart/form-data"

>

<

input

type

="file"

class

="col-xs-4 up_file"

name

="productfile"

value

=""id

="filename"

>

<

a class

="btn btn-xs btn-primary btn-outline col-xs-2 product_upload"

><

span

class

="fa fa-upload"

>

span

> 上傳商品

a>

form

>

js部分:

//

通過上傳**,新增商品資料

$(".product_upload").live("click",function

() }

else

if(res.error==1)

else

},error :

function

(res)

});});

控制器controller:

//

上傳商品的資料

public

function

actionproduct_data_upload()

}$phpexcel = $phpreader->load($filepath

);

/**讀取excel檔案中的第乙個工作表

*/$currentsheet = $phpexcel->getsheet(0);

/**取得一共有多少行

*/$allrow = $currentsheet->gethighestrow(); //

行數$remind = array

();

$product = array(); //

商品資料無誤的情況下,上傳資訊

$i = 0; //

商品資訊錯誤的條數

$j =0; //

商品資訊無誤的條數

for ($currentrow = 2; $currentrow

<= $allrow; $currentrow++)

else

' and f_is_shelves=1");

if (!$exists

)

}if($flag==0)

' and f_is_shelves=1");

if($detail->f_id)

}$i++;

}//上傳資料格式不對。將錯誤資訊返回到頁面

if (count($remind)>=1)

else

}else

}

FormData通過ajax上傳檔案

bt click function function sumitimagefile base64codes,thisobj xhr function false return xhr 將以base64的url資料轉換為blob param urldata 用url方式表示的base64資料 func...

通過ajax上傳excel

html 上 傳 匯入格式 xls js 匯入檔案 function importexp success function responsestr else controller service 寫入 param is public string writeexeldata inputstream ...

Ajax解決非同步表單(包含檔案上傳)提交

不包含檔案的表單 1.前端 提交表單2.控制器 包含檔案的表單 1.前端 確認上傳 2.控制器 controller public class fileuploadcontroller try catch ioexception e 存放上傳的資料夾 file filedir uploadutils...