Note that the point on the rear end of the receiving ajax, axios request format

First distinguish contentType and dataType

$.ajax({
    dataType: 'json',
    contentType: 'application/json',
    data: JSON.stringify({a: [{b:1, a:1}]})
})

contentType : tell the server what kind of data I want to send

dataType : tell the server what type of data I want, if not specified, it will automatically infer that the return XML, or JSON, or script, or String.

var formData = new FormData();
formData.append("image", this.file);
formData.append("name", this.bean.name);

axios.put(url, formData).then(function(response){
	if(response.data.code==1){
		location.href = vue.skip_url;
	}
	else{
		alert("提取数据失败...");
	}
});

1, when the data transfer FormData request format multipart / form-data, only the rear end of the write parameter name corresponding to the key can be received.
2, when a transmission form form data, the request format is application / x-www-form- urlencoded, key = value form, only the rear end of the key corresponding to the parameter name written can receive.
3, when an object is conveyed, the request format is application / json, we will use the rear end of the receiving entity to the @RequestBody

Https://blog.csdn.net/qq_39641912/article/details/79862914 references
cited https://blog.csdn.net/john1337/article/details/60867183

Published 54 original articles · won praise 1 · views 1839

Guess you like

Origin blog.csdn.net/qq_42039738/article/details/104565761