开发者

Accessing a passed variable from JQuery to Rails controller

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜