在用fetch进行表单提交时,参照https://github.com/github/fetch的用法
let data = new FormData(document.getElementById('login-form'))
fetch('../membership/authenticate', {method: "POST",
headers:{
'Content-Type': 'application/x-www-form-urlencoded'
},
body: data}).then(function(response) {
},function(error){
})
格式被转为了WebKitFormBoundary模式:
此时我后端springMvc是取不到Key值。
明明已经设置了ContentType为application/x-www-form-urlencoded,设置 enctype 属性,那么最终就会以 application/x-www-form-urlencoded 方式提交数据。提交的数据按照 key1=val1&key2=val2 的方式进行编码,key 和 val 都进行了 URL 转码。
却还是按照multipart/form-data提交,
如果按照如下格式则能够正常取得到值:
let data = 'username=' + values.username + '&password=' + values.password;
fetch('../membership/authenticate', {method: "POST",
headers:{
'Content-Type': 'application/x-www-form-urlencoded'
},
body: data}).then(function(response) {
},function(error){
})
版权声明:本文为echo_oy原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。