开发者

Accessing a passed variable from JQuery to Rails controller

开发者 https://www.devze.com 2023-03-07 18:57 出处:网络
I have this JQuery code: $(\"div.notification\").live(\"click\", function(){ window.location=$(this).find(\"a\").attr(\"href\");

I have this JQuery code:

    $("div.notification").live("click", function(){
        window.location=$(this).find("a").attr("href");
        var myId = $(this).attr("id");开发者_如何学Python
        $.post("/videos/selected_notification.js", myId);
        return false;
    });

I want to be able to access myId from inside my controller that the post request hits. How do I do this?


Give your myId value a name and you can pull it out of params just like any other POST parameter:

$.post("/videos/selected_notification.js", { id: myId });

And then, in the controller:

id = params['id'] # Or params[:id] since params is a HashWithIndifferentAccess
0

精彩评论

暂无评论...
验证码 换一张
取 消