简体   繁体   中英

Using JQuery to render a form on click of link Rails

I am trying to get the Jquery to render a form on click of a link.

This is the link to click.

<%= link_to 'Try Link', new_user_path, :remote=>true, :class=>'create_user' %>

I have a class here which renders a form. I want to change it such that it would only show after the button is clicked.

<div class = "TestClass"><%= render 'form'%></div>

The javascript: Right now I am able to change the text in the div class but I am not sure how I should go about putting the render form in the javascript.

$('.create_user').bind('ajax:success', function() { 
    //alert("Clicked");
    $(".TestClass").text("Ajax success");
}); 

I would appreciate it if someone could just point me in the right direction.

In your controller, make sure you render your view with no layout. Then you can easily do something like :

$('.create_user').bind('ajax:success', function(evt, data) { 
    $(".TestClass").html(data);
}); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM