[英]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.