HTML代码
JS代码
var file_obj = document.getElementById(search_key_file).files[0];
console.log(file_obj);
if (typeof (file_obj) == "undefined") {
toastr.error("请选择需要导入的搜索词文件");
return;
}
var type = $("input[name=search_key_type]:checked").val();
var fd = new FormData();
fd.append(accountId, searchKeyAccountId);
fd.append(file, file_obj);
fd.append(type, type);
$.ajax({
url: /**/**,
type: POST,
data: fd,
processData: false, //tell jQuery not to process the data
contentType: false, //tell jQuery not to set contentType
//这儿的三个参数其实就是XMLHttpRequest里面带的信息。
success: function (result, a1, a2) {
result = JSON.parse(result);
if (result.code == 0) {
toastr.success("导入成功");
var temp = document.getElementById(search_key_file);
temp.outerHTML = temp.outerHTML;
cancelXhrSubmit();
} else {
toastr.error(result.msg);
}
}
})
清除上一次选中的文件
var temp = document.getElementById(search_key_file);
temp.outerHTML = temp.outerHTML;