js提交文件或图片,同时提交到2个服务器上

使用element,

<el-upload class="upload-demo" :action="url_action_Cont" :on-preview="handlePreview"

:on-remove="handleRemove" :on-success="onsuccess" :ref="fileList"

accept=".doc,.docx,.pdf,.png"

:on-exceed="handleExceed" :file-list="fileList" :beforeUpload="beforeAvatarUpload">

<el-button size="mini" type="primary" >点击上传</el-button>

</el-upload>

以下是js,在beforeAvatarUpload之前传到另一个服务里

beforeAvatarUpload(file){

var formData = new FormData();//初始化一个FormData对象

formData.append("file", file);//将文件塞入FormData

console.log(formData)

$.ajax({

url: this.url_action,

type: "POST",

data: formData,

processData: false,

contentType: false,

success: function (responseText) {

}

});

}

 

 

上一篇:libcurl第七课 multipart/formdata表单使用


下一篇:解决ajax异步上传文件的问题