[英]Post cvs data with ajax
我試圖用ajax發布數據,但在控制台中我收到類似..未捕獲的ReferenceError:文件未定義
這是我用按鈕上傳數據的輸入:
<div id='file_browse_wrapper'>
<input class="iconos" type="file" name="File Upload" id='file_browse' accept=".csv" />
</div>
<label id="url-archivo"><b>Selecciona tu archivo...</b></label>
<button class="btn btn-success" id="carga-archivo">Subir</button>
這是我的jquery / ajax:
$("#carga-archivo").click(function () {
var fileUpload = document.getElementById("file_browse");
if (fileUpload .value != null) {
var uploadFile = new FormData();
var files = $("#file_browse").get(0).files;
// Add the uploaded file content to the form data collection
if (files.length > 0) {
uploadFile.append('file-'+i, file);
$.ajax({
url: "/2/delivery/client/massive",
contentType: false,
processData: false,
data: uploadFile,
type: 'POST',
success: function () {
alert("file upload successfuly");
}
});
}
}
});
但是數據不是POST,我認為缺少了一些
您已經創建了一個名為files
的變量,但是正在使用一個名為file
的變量。 嘗試更改代碼的這一部分:
var file = $("#file_browse").get(0).files;
// Add the uploaded file content to the form data collection
if (file.length > 0) {
uploadFile.append('file-'+i, file);
$.ajax({
url: "/2/delivery/client/massive",
contentType: false,
processData: false,
data: uploadFile,
type: 'POST',
success: function () {
alert("file upload successfuly");
}
});
}
這只是將files
變量重命名為file
並在另一個使用files
地方進行了更改。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.