发出AJAX请求到正确的URL [英] Making an AJAX request go to the right URL
问题描述
我在一些自动完成的jquery代码中有这个ajax请求:
I have this ajax request inside some jquery code for autocomplete:
$.ajax({type:"POST", url:("showable_videos/create.js"), data:{video:{profile:val}}});
自动完成功能作用于我的视频节目视图内的字段.因此,当它发出AJAX请求时,出现此错误:
The autocomplete acts on a field that is inside my video show view. Therefore, when it makes the AJAX request I get this error:
Started POST "/videos/showable_videos/create.js" for 127.0.0.1 at Tue Apr 26 00:18:33 -0700 2011
ActionController::RoutingError (No route matches "/videos/showable_videos/create.js"):
当我希望/showable_videos/create.js
仅是/showable_videos/create.js
时,Rails会将URL放在/videos/
之前.我该如何解决?
Rails is prepending /videos/
to the URL when I want it to just be /showable_videos/create.js
. How can I fix this?
推荐答案
因为您没有提供绝对路径(以"/"为根的绝对路径),所以rails会将其解释为从当前路径"而不是从根" .
since you didn't provide an absolute path (one rooted with "/") rails interprets that as "from the current path" instead of "from the root".
最好使用Rails路径帮助程序,而不是像这样对URL进行硬编码.
It's best to utilize rails path helpers instead of hard coding the urls like that.
这篇关于发出AJAX请求到正确的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!