我正在尝试使用提取polyfill“ whatwg-fetch”发布请求(窗体)。虽然这在Chrome和FF中有效,但在IE和Edge上似乎无效。
import 'whatwg-fetch';
const dataObject = {
'a' : 'b'
}
const params = new URLSearchParams();
params.append('someData', JSON.stringify(dataObject));
fetch(url, {
method: 'POST',
mode: 'cors',
cache: 'no-cache',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
},
redirect: 'follow',
referrer: 'no-referrer',
body: params,
}).then((res) => {
console.log(res);
}).catch((e) => {
console.log(e);
});
在IE和Edge中,此代码不会发送请求并捕获异常:
e Failed to execute 'fetch()' on 'Window': Invalid argument.
有什么想法吗?
答案 0 :(得分:1)
我遇到了完全相同的问题,在我的案例中,我帮助添加了这样的标头和 .toString():
...
headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
body: form.toString()**
...
答案 1 :(得分:0)
嗨-看来确实是加载问题。
您只需尝试
//variable starts here
firstName:any;
lastName:any;
email:any;
changePassword:any;
currentPasswordText:any;
newPasswordText:any;
ConfirmPasswordText:any;
data={
"isActive": false,
"role": "admin",
"permissions": ["101", "202"],
"_id": "5b39e0d0be883b029870bfc8",
"firstName": "Anish",
"lastName": "Kumar",
"emailId": "anish@gmail.com",
"password": "$2b$10$sQ1CCrtRy/Hvd3p3tje7t.A4.G7Jt2ayoETpniW8RlWSjkj1H77l2",
"mobileNumber": "95990709xx",
"createdAt": "2018-07-02T08:22:40.223Z",
"__v": 0
};
//variable ends here
//Add this line for assign values to textbox wherever you want
this.firstName=this.data.firstName;
this.lastName=this.data.lastName;
this.email=this.data.emailId;
this.currentPasswordText=this.data.password; // the password has been encrypted you have to decrypt
updateUser(formData){
console.log("Form Value",formData.value); //here iam logged form value
}
在 index.html 中,检查其是否正常运行。