jQuery AJAX to Rails 3, In Rails how to get the Variable Passed via Data?
Rails 3 app.... I have the following jQuery which is working:
$.ajax({
url: '/navigations/sidenav',
data: "urlpath=" + urlpath,
success: function(e){
$("#sideNav-container").slideDown("slow");
}
});
urlpath can be paths like '/' or '/projects' or '/authors' s开发者_如何转开发tuff like that.
My question is how do I grab that urlpath variable in the controller so I can use it in my view to determine what sidenav to return to the user?
Thanks
Pass in the urlpath in a hash for the "data" key. Like so:
$.ajax({
url: '/navigations/sidenav',
data:{"urlpath":urlpath},
success: function(e){
$("#sideNav-container").slideDown("slow");
}
});
This will then pass urlpath in the params object, that you can access from your controller. So you can simply do
params[:urlpath]
and you can get the urlpath you passed in. :)
精彩评论