Project axios request to send post data type when stepped on Form Data data pit (set up after the request has not been successful header information sent in the past but not the type) Solution

Post projects on the rear end of the data transmission requirements of formdata,

  • Then the first thing now setup request header ,, with many package ajax libraries may request header information provided herein as an example to axios
axios({
    url:this.dialog.add.upload_url,
    method:'post',
    data,
    headers:{
        'Content-Type':'application/x-www-form-urlencoded'
    }
}).then(res=>{
    if(res.status){
        this.$message.success("修改成功");
        this.mapping=[];
        this.dialog.add.show=false;
        this.getTableData();
    }
})
Here the object is a data
 let data = {
 		temp_name:"sjsj",
 		mapping:[{'sda':'dad'},{'sda':'dad'}]
 }

But in the past this type of transmission data is correct, but he is not formatted correctly so that the rear end of the received data might not be processed
Here Insert Picture Description

A new solution FormData () but do not do as the data sent is in fact not formdata
let data=new FormData();
data.append("mapping",this.fileUploadData.mapping)
data.append("temp_name",this.fileUploadData.temp_name)
data.append("_id",this.fileUploadData._id)
Now let's look at network

Here Insert Picture Description

That's all we want to help

Released two original articles · won praise 2 · Views 140

Guess you like

Origin blog.csdn.net/weixin_42409911/article/details/104651232