javascript - Bootstrap Modal won't close, previously appended to Body using JQuery -


So I go to all the difficulties to get a modal and working text box, then I close it Go to the AJAX success event, but nothing seems to work I'll try.

  var id; Var refundarm = ''; Var Token = $ ("Meta [name = 'CSRF-Token']"). Attr ('content'); $ ('[Data-Toggle =' Model ']'). Find ID from ('click', function (e) {var checkEventCount = 1; var prevTarget; // Models href attribute ID = $ (this) .attr ('href'). (/ [^ 0-9.] / G, ""); $ ('# new_refund_modal' + id) .on ('show.bs.modal', function (e) {if (prevofarget == 'undefined' || (CzechEventCount == 1 & amp; Amp; e.target! = PrevTarget)) {prevTarget = e.target; CzechEventContent ++; E.Pravant Default (); $ (E.T. ('$'), ('$'), () () () () (Value)) = Refund Amount (Refund amount = $ (this) .val ();}});} And if (e.target == Navigate & amp; amp; Number == 2) {checkeventcount--;}});}); $ ('Refund-deposit-BTN') Click (function (e) {e.preventDefault (); $ .ajax ({url: '& lt;% = payment_plan_refund_url% & gt;', type: 'post', data: {Authenticity_token: token, id: id , Payment: {refund_arthry: refund amount}}, success: function (data, position) {$ ('# new_refund_modal' + id). Model ('hide');}})}};  

Here I have given a list of different fixes, which I have tried, the Close button in the modal mode still works, so I try to trigger it on AJAX success But I'm not sure whether the work is either

  1) $ ('# new_refund_modal' + id). Model ('hide'); 2) $ ('# new_refund_modal' + ID). Data ('model', empty); 3) $ ('# new_refund_modal' + ID) .remove (); ('.modal-background'). $ Deletion (); $ ('Body') removeClass ('average to open'). 4) $ ('#modelmodel' id). Click ();  

All previously registered event handlers are run when you delete / add element For example, this is your DOM tree:

  body + - modal1  

+ - close-button

If you register the handler on the clock-button, when modal1 is removed from the DOM / added again, the handlers have gone. It is also applicable if the handler has created modal1 before the handler and connected to the DOM

You can either reload the handler when you delete / re-add the DOM element , Or register the handler on the ancestor elements (because the element that triggers the trees will spread to the top).

For example, click

  $ ('# modal1.close-button' '(' click ',' ''). Click (function () {..})  

Use:

  $ ('body'). # Modal1. Close-button '. Function () { ..});  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -