Reputation: 2122
I have 2 javascript files included in a popup (simple div) generated using ajax.
<script type="text/javascript" src="<?php echo JS ?>pm.js"></script>
<script type="text/javascript" src="<?php echo JS ?>chat.js"></script>
When you close the popup and re-open it, the jQuery bound functions in the two files execute twice.
for example
//connection
$(document).bind('connect', function() {
var conn = new Strophe.Connection('my-http-binding-url');
conn.connect(inbox.data.jid, inbox.data.pass, function(status){
inbox.connection = conn;
alert(status)
});
});
First time I open the popup, it displays the alert message : 5, which means it connected successfully.
But when I close the popup, and re-open it, it shows me the message twice... I assume the code is executed twice because it's not unloaded.
Upvotes: 0
Views: 221
Reputation: 1752
You can achieve by following two different way
Note: You can not remove javascript once it loaded. Use "Firebug" or "Chrome Developer Tool" 's Network tab and make sure that javascript is not loaded multiple time.
Edit: You can access the dynamic HTML after ajax completed
$.ajax({
...,
...,
success: function afterAjax(){
// Insert dynamic HTML in Document
// Any jQuery selector/function you can use here
}
}
Upvotes: 2