javascript - jQuery bind ajax:success not working in rails 3 app for newly created (ajax) items -


** This post was edited because I think that this problem is actually connected to Ajax in the inability to rail: success Function.

*** Using Rails 3.2.3

Thanks for taking the time to try and help out.

I'm adding a simple Fade Out function to AJAX: The success of an item is being deleted, such as:

  $ (document) .ready (jQuery (function ($) {$ ('. Delete'). Tie ('ajax: success', function () {$ (this) .clostest ('div'). FadeOut ();});})); # For some reason it had to pass INR $ in the function to make it work, to make sure why this is necessary, but it does not work until it is complete.   

After this, I wanted to make an object with incredible jQuery while adding something to the user, and even the deleted buttons have to work on them. I have created a create.js.erb file that is called after creating a new item - and the creation works well, but the deleted buttons can not access AJAX: Success event.

When this data is clicked on DB, however. If the fade is not bound for it, then it does not disappear. Create.js.erb is as follows:

  # $ ("div"). Endend (html) here, then try and force AJAX to call the function given below: Success Function $ ('.delete'). Tie ('Ajax: complete', function () {$ (this) .clostest ('div'). FadeOut ();});   

If I change it to bind it on the click function, it works, but it does not have an account for a failed Ajax call:

 < Code> # $ ("Div"). Endend (html) here, then try AJAX to call the function given below: Success Function $ ('Delete.'). Bind ('click', function () {$ (this) .closest ('div'). FadeOut ();});   

Then some Ajax should be compelled to: Success after the item is created. Do you know why this can happen? To identify the events of Ajax, do I have to do something special in the train to get the new sung item? Any direction will be appreciated!

P.S. In the case given below, the controller of the deletion method may be able to detect the problem:

  Delete def @user = user.phid (param [: user_id] ) @ Etem = @ User .item.find (params [: id]) @ item.destroy response_to do | Format | Format.html {redirect_to user_path (@user)} format.json {head: no_content} format.js {render: nothing => True} ending  

The element sounds like the binding is before the sound is generated. Try it:

  $ (document) .on ('ajax: success', '.delete', function (e) {$ (e.currentTarget) .closest ('div'). fade out(); });    

Comments