我的反应应用程序中的 PUT 请求有一些问题。我正在使用带有标准提取请求的 redux-form。当我发送请求时出现错误:PUT http://localhost:8080/auth 500 (Internal Server Error) "SyntaxError: Unexpected token <" 有我的获取代码:
export default async function submit(fields, dispatch) {
console.trace()
const {email, fullName, company, industry, phone} = fields
let errors
if (!email)
errors = {
...errors,
email: 'Email cannot be empty'
}; else if (!/[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}/i.test(email))
errors = {...errors, email: 'Email seems invalid'};
if (!fullName)
errors = {...errors, fullName: 'Full name cannot be empty'};
if (!company)
errors = {...errors, company: 'Company name cannot be empty'};
if (!industry)
errors = {...errors, industry: 'Industry should be selected'};
if (errors) {
return Promise.reject(errors)
}
const response = await fetch('/auth', {
credentials: 'same-origin',
method: 'PUT',
body: Object.keys(fields)
.filter(prop => fields[prop] !== undefined)
.reduce((fd, prop) => {
fd.append(prop, fields[prop])
return fd
}, new FormData())
});
if (response.ok) {
console.log('good');
console.log(response);
} else {
const data = await response.json();
console.log('bad');
console.log(response);
}
}
它有什么问题?