smugford
smugford

Reputation: 83

unload ajax when just closing a jquery ui dialog

i'm using this technique to load ajax into a jqueryui dialog

load ajax dialog technique

it works fine

except for one this with my in my implementation

i have a calculation that i have put in the "complete" section...

options.complete = function(){
$("#quantity").bind("keyup",
                        function () {
                            var sum = 0;
                             price = $('#price').val();
                             qty =   $('#quantity').val();
                             sum = price*qty;

                            $('.total').text(sum);
 });        
}

That works fine on the first load every time. If i refresh it works like a charm.

I even tried the live method.

like this....

options.complete = function(){
 $("#quantity").live("keyup",
                        function () {
                            var sum = 0;
                             price = $('#price').val();
                             qty =   $('#quantity').val();
                             sum = price*qty;

                            $('.total').text(sum);
 });        
}

using the live method i get some interesting if i alert out a alert('here') at the top of the function.

each time i open and close the dialog and change the number in the quantity i get as many alerts as the amount of times that i have opened and closed the dialog

ie : open and close the dialog 3 times and i get 3 alerts....open it 5 times i get 5 alerts etc etc.

what i need to know is if there is a way to completely unload the ajax from the DOM with the jquery ui dialog beforeClose: method.

Thanks in advance.

Scott

oops forgot to put this in as well...

  "Cancel": function() {
            $(this).dialog("destroy");   
                            }   

also does not work.

Upvotes: 0

Views: 799

Answers (2)

charlietfl
charlietfl

Reputation: 171669

If you use a delegation method like live() , call it outside of other event handlers so it doesn't get bound repeatedly when your other events occur more than once. Live doesn't even need to be called inside $(document).ready() since it is delegated to the document.

Upvotes: 1

Vigrond
Vigrond

Reputation: 8198

Sounds like you need to destroy() the dialog after closing it.

Upvotes: 0

Related Questions