【发布时间】:2014-12-29 02:56:25
【问题描述】:
我正在尝试创建 ajax 调用并使用文件和其他变量发送数据,如果有帮助,我也会使用 django。
我的尝试:
js文件:
$("#save-new-request-testBtn").click(function(){
var project = $('#project').val();
var newRequestStreams = $('#newRequestStreams').val();
var request_bot_file = $('#request_bot_file')[0].files;
submit_new_request(project,newRequestStreams,request_bot_file );
});
function submit_new_request(project,newRequestStreams,request_bot_file ){
url= "add/submit";
console.log(project);
var new_data;
csfr();
$.ajax({
async:false,
url: url,
type: "POST",
enctype: 'multipart/form-data',
data: ({project:project,newRequestStreams:newRequestStreams,request_bot_file :request_bot_file }),
success: function(data){
new_data= data;
console.log(data);
},
error: function(xhr, status, error) {
$("#formError").html(xhr.responseText);
console.log(xhr.responseText);
}
});
console.log('fgcfg');
return new_data;
}
问题在于文件的选择: 未捕获的 InvalidStateError:无法从“HTMLInputElement”读取“selectionDirection”属性:输入元素的类型(“文件”)不支持选择。
有什么好的建议如何让它发挥作用?
谢谢, 冷杉
【问题讨论】:
-
你有什么问题?
-
这是正确的方法吗?因为它不起作用?
-
哪个部分不完全工作?
-
准确查找问题。
-
问题在于文件的选择:未捕获的 InvalidStateError:无法从“HTMLInputElement”读取“selectionDirection”属性:输入元素的类型(“文件”)不支持选择。
标签: jquery ajax django html file-upload