[英]Rails ajax call 404 not found routing error
I was playing around with ruby on rails and tried making ajax call but kept seeing an error. 我当时正与Ruby在轨道上玩耍,并尝试进行ajax调用,但一直看到错误。 So in my index.html.erb, I have a button with id test.
因此,在我的index.html.erb中,我有一个带有ID测试的按钮。 And in the same index file, I have
在同一个索引文件中
("#test").click(function(){
$.ajax({
type: 'POST',
url: '/test',
data: {key: 'value'},
dataType: 'script',
});
});
So, when I click on the button with id test, I keep seeing 因此,当我点击ID测试按钮时,我一直在看到
POST http://localhost:3000/test 404 (Not Found)
I cannot seem to figure out why because in my config/routes.rb, I have get '/test', to: 'prompts#test' and in my promptsController, I have 我似乎无法弄清楚为什么,因为在我的config / routes.rb中,我得到了'/ test',到:'prompts#test',在我的hintsController中,我得到了
def test
puts "enters here"
end
In your routes you say you have 在您的路线中,您说您有
get '/test', to: 'prompts#test'
But notice that in your call to $.ajax()
you're using POST . 但是请注意,在调用
$.ajax()
您正在使用POST 。
Instead you need a route for 相反,您需要一条路线
post '/test', to: 'prompts#test'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.