ujs

ajax:success and ajax:complete callback doesn't work when using UJS in Rails

隐身守侯 提交于 2019-12-01 08:28:06
I have a link that when i click on it will trigger an ajax call then replace this link by another link, says for example the original link is "add friend", when i click this link it will send an ajax request to add_friend action then if the friend is added the link above will be replaced by another link "cancel request", i use ujs for that : $("#link_for_friend").html("<%= escape_javascript(render('users/cancel_link')) %>") when i try to add callback (:success and :complete) it doesn't works, i tried with :beforeSend like the following it works : $(document).ready -> $("#my_link").on "ajax

ajax:success and ajax:complete callback doesn't work when using UJS in Rails

南笙酒味 提交于 2019-12-01 04:16:47
问题 I have a link that when i click on it will trigger an ajax call then replace this link by another link, says for example the original link is "add friend", when i click this link it will send an ajax request to add_friend action then if the friend is added the link above will be replaced by another link "cancel request", i use ujs for that : $("#link_for_friend").html("<%= escape_javascript(render('users/cancel_link')) %>") when i try to add callback (:success and :complete) it doesn't works,

Rails 4: Disable submit button after click

限于喜欢 提交于 2019-11-30 07:27:40
问题 I have a form_tag(foo_path(@foo), remote: true, id: 'foo-form' form and a submit button submit_tag ("Submit", :id => "foo-submit") I'd like to disable the submit button after it has been clicked. Obviously, I cannot use something like onlick="jQuery(this).prop('disabled', true);" because it would break the remote functionality. I'm aware of the :disable_with data attribute for the submit_tag but it doesn't seem to work for me. It does generate the right form code but it has no effect. I'm not

Why is Rails UJS ajax:success bind being called twice?

独自空忆成欢 提交于 2019-11-30 05:44:54
问题 I have a simple form: = form_for(posts_path, :id => "new_post", :remote => true) do = text_field_tag "post[input]" = submit_tag "Post!" I have bound a callback to the ajax:success event: $("form#new_post").bind("ajax:success", function(xhr, data, status){ alert("Post Created!"); }); When I click the Post! button, the Post Created comes up twice . Why? I'm using Rails 3.1 which by default is using jquery-ujs. 回答1: That is because your page is loading jquery_ujs code twice in development mode

Simple example of Rails 3 + UJS using Ajax to make a remote call, and rendering the resulting JSON object

限于喜欢 提交于 2019-11-30 05:19:29
I'm trying to add some Ajax functionality in my Rails 3 app. Specifically, I want a button that will submit an Ajax request to call a remote function in my controller, which subsequently queries an API and returns a JSON object to the page. Once I receive the JSON object I want to display the contents. All of this with the new Rails 3 UJS approach, too. Is there a good example/tutorial for this online somewhere? I haven't been able to find one on google. A simple example using a button as the entry point (ie, the user clicks the button to start this process) would work, too. Edit Let me try

Element.update is not a function [Rails 3 + JQuery]

拥有回忆 提交于 2019-11-29 07:56:38
I'm attempting to integrate JQuery into Rails 3. I've downloaded the rails.js file from http://github.com/rails/jquery-ujs and have included it in my app. I've also include JQuery. But when I attempt to do a simple page.replace like so: render :update do |page| page.replace_html "my_div", :partial => "my_partial", :locals => {:mylocal => mylocal} end I get the following error thrown from the javascript executing: RJS error: TypeError: Element.update is not a function Element.update("my_div", "mypartialdata"); Any ideas? As others have said, page.replace , in rails 2, references Element.update

Rails 4: Disable submit button after click

点点圈 提交于 2019-11-29 04:12:36
I have a form_tag(foo_path(@foo), remote: true, id: 'foo-form' form and a submit button submit_tag ("Submit", :id => "foo-submit") I'd like to disable the submit button after it has been clicked. Obviously, I cannot use something like onlick="jQuery(this).prop('disabled', true);" because it would break the remote functionality. I'm aware of the :disable_with data attribute for the submit_tag but it doesn't seem to work for me. It does generate the right form code but it has no effect. I'm not sure why it doesn't work but it might be due to the fact that I use prototype (legacy reasons) and

Simple example of Rails 3 + UJS using Ajax to make a remote call, and rendering the resulting JSON object

南笙酒味 提交于 2019-11-29 02:53:31
问题 I'm trying to add some Ajax functionality in my Rails 3 app. Specifically, I want a button that will submit an Ajax request to call a remote function in my controller, which subsequently queries an API and returns a JSON object to the page. Once I receive the JSON object I want to display the contents. All of this with the new Rails 3 UJS approach, too. Is there a good example/tutorial for this online somewhere? I haven't been able to find one on google. A simple example using a button as the

Simple like/unlike button with rails 3, jquery, and ajax

烈酒焚心 提交于 2019-11-28 18:59:53
I have a product, user, and like model. A user can like a product. I am trying to implement a simple like button which, upon a click, allows a user to like a product. Then the like button transforms into an unlike button, allowing the user to unlike a product. Pretty straightforward. I have implemented the model/controller logic for the above. I am not very good with javascript/ajax and was wondering what the best way would be to implement the above functionality. I want the like/unlike actions to be handled via ajax. I am using rails 3 and jquery ujs for my app. Thanks. My answer to your

Element.update is not a function [Rails 3 + JQuery]

我与影子孤独终老i 提交于 2019-11-28 01:26:08
问题 I'm attempting to integrate JQuery into Rails 3. I've downloaded the rails.js file from http://github.com/rails/jquery-ujs and have included it in my app. I've also include JQuery. But when I attempt to do a simple page.replace like so: render :update do |page| page.replace_html "my_div", :partial => "my_partial", :locals => {:mylocal => mylocal} end I get the following error thrown from the javascript executing: RJS error: TypeError: Element.update is not a function Element.update("my_div",