后CVS与阿贾克斯数据
问题描述:
我试着与阿贾克斯,但在控制台我recive像发布数据..未捕获的ReferenceError:文件中没有定义后CVS与阿贾克斯数据
这是我与我的按钮来上传数据输入:
<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");
}
});
}
}
});
但数据没有职位,我认为这是若有所失
答
您已创建一个名为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
的另一个地方。
+0
@victor如果这回答了您的问题,请点击答案旁边的复选标记以接受它。选中标记颜色将变为绿色以显示它已被接受。如果您有任何问题或有新的信息,请让我知道,我可以提供更新的答案。 –
正是它所说的。你在哪里设置/定义“文件”? –
我从我的输入中捕获文件 – victor
您不知道。变量'file'没有被定义。 –