【发布时间】:2020-03-08 00:01:57
【问题描述】:
我在 Vue.js 客户端中运行 DELETE 请求时遇到问题。这是我现在的代码,我只是对链接进行硬编码以便试用。
deleteCompany(){
axios.delete('http://localhost:9292/companies/1')
.then(response =>{
console.log(response);
});
}
在后端,我有一个用 Sinatra 构建的 Ruby 服务器,这是 DELETE 的方法:
#delete a company
delete '/companies/:id'do
content_type :json
company = Company.get params[:id]
if company.destroy
status 200
json'Company was deleted'
else
status 500
json 'There was problem removing the company'
end
end
我尝试使用 curl 和 Postman,它正在工作,但是当我尝试从客户端执行此操作时,它给了我一个 CORS 错误,尽管 POST 等其他方法正在工作:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:9292/companies/1. (Reason: Did not find method in CORS header ‘Access-Control-Allow-Methods’).
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:9292/companies/1. (Reason: CORS request did not succeed).
【问题讨论】:
标签: ruby vue.js cors axios sinatra