![](/img/trans.png)
[英]Axios post request failure from React front end to Laravel and mysql
[英]Rails is seeing a post request as a get, with a react front end
我有一個帖子請求:
axios.post("/api/main/products/area_home_products.json"
然后在routes.rb
中:
namespace :api do
namespace :dashboard do
....other routes...
end
namespace :main do
post '/products/area_home_products', to: 'products#area_home'
一切正常,然后突然之間,controller 操作或 js 文件沒有重大變化,我得到:
No route matches [GET] "/api/main/products/area_home_products.json"
不是第一次出現這種情況,不知道為什么會這樣,也不知道怎么解決
做rake routes | grep area_home_products
rake routes | grep area_home_products
,明白我的意思;
api_main_products_area_home_products POST /api/main/products/area_home_products(.:format) api/main/products#area_home
api_v1_products_area_home_products POST /api/v1/products/area_home_products(.:format) api/v1/products#area_home
axios({
method: 'post',
url: '/api/main/products/area_home',
headers: { 'Access-Control-Allow-Origin': '*', 'Accept': 'application/json',
})
你可以用api這個方法撥打。 另外,像這樣更新您的路線:
namespace :api do
namespace :main do
resources :products do
collection do
post :area_home
end
end
end
end
這是因為您的請求標頭有問題,因為您正在使用 url 中的 json,這可能會誤導它,而且您沒有使用足智多謀的路由,或者您的 api 配置不正確。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.