使用jQuery GET作为表单数据输入的jQuery ajax POST

问题描述

我正在尝试调用一个jquery ajax POST请求,该请求具有formdata作为位于文件服务器上的多个文件。 这是我的ajax请求;

var formData = new FormData();
$.ajax({
        url: 'url',method: 'POST',contentType: false,processData: false,data: formData,beforeSend: function (xhr) {
            xhr.setRequestHeader ("Authorization","Basic " + btoa(username + ":" + password));
        },success: function(res){
            console.log('successfully')
        },error: function(){
            console.log('error')
        }
    })

其中formData的文件位于文件服务器上的某个位置,我尝试使用jquery get来获取文件,并尝试在准备好的文档上添加formData,如下所示;

$.get("http://localhost/file.xml",function(data) { 
    var data1 = data;
    var file = new File([data1],"file.xml");
    formData.append('file',file);
});

是否可以在ajax POST请求中传递或创建具有位于文件服务器上的文件的formData?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)