【问题标题】:post fetch method is not working using placeholder typicodepost fetch 方法无法使用占位符 typicode
【发布时间】: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


【解决方案1】:

请完全删除提取选项对象

{ method: 'POST' }

来自您的电话。

这个电话应该是GET 而不是POST

【讨论】:

  • 为什么要删除这个?是post方法
  • 好的,既然 jsonplaceholder 在所有路由上都支持 GET 和 POST,那么这对他们来说是个问题。邮递员的请求也失败了。 GET工作正常
  • 他们可能有什么问题?
猜你喜欢
  • 2015-04-01
  • 2014-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-12
相关资源
最近更新 更多