This is my jquery code
$.ajax({ url: "PopUpProductDetails.aspx", cache: false }).done(function (html) { $("#dialog").append(html); });
The first time, it works just fine. It display the content of the PopUpProductDetails.aspx page. But, after that, If I click again, I get twice the same content, and so forth. I believe the problem is that I need to clear the dialog element first, before appending new content.
How do I do that?
Approach 1: Initially use removeClass() method to remove active class of previously appended data menu item. Then followed by addClass() method to add active class of currently appended data menu item. Now use each() function to append data with respect active class added or removed on click.
jQuery uses: . append(); and . remove(); functions to accomplish this task. We could use these methods to append string or any other html or XML element and also remove string and other html or XML elements from the document.
The . append() method inserts the specified content as the last child of each element in the jQuery collection (To insert it as the first child, use . prepend() ).
.append()
appends html to the end of existing html string, use .html()
to replace what's currently inside of #dialog
.
Inside the function clear the dialog first and then fill up with the content
$.ajax({ url: "PopUpProductDetails.aspx", cache: false }).done(function (html) { $("#dialog").html(""); $("#dialog").html(html); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With