【发布时间】:2020-06-02 12:23:54
【问题描述】:
fetch('https://jsonplaceholder.typicode.com/posts', {
method: 'POST'
}).then(function (response) {
// The API call was successful!
if (response.ok) {
return response.json();
} else {
return Promise.reject(response);
}
}).then(function (data) {
// This is the JSON from our response
console.log(data);
}).catch(function (err) {
// There was an error
console.warn('Something went wrong.', err);
});
post fetch 方法不起作用尝试下面的代码没有响应任何响应可能是什么原因请指导
获取失败的 net err_failed typicode 占位符
或可能访问从源“https://cdpn.io”获取“https://jsonplaceholder.typicode.com/posts”已被 CORS 策略阻止:请求的资源上不存在“Access-Control-Allow-Origin”标头。如果不透明的响应满足您的需求,请将请求的模式设置为“no-cors”以获取禁用 CORS 的资源。
【问题讨论】:
-
发生网络错误
标签: javascript