在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,它正在工作,但是当我尝试从客户端进行操作时,尽管其他方法(例如POST)正在工作,但它却给我一个CORS错误:
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).
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句