I’m having a pickle with my jQuery. The situation is as follows:
I’m having a page loaded (main page). When clicked on a certain element, a div is opened loaded with another page(page1). Within this loaded page, I have a button, which opens a dialog, containing another loaded page (page2).
This all works fine, for one time. When I close the dialog, it doesn’t appear again when clicked on the button on page1.
I’ve searched the interwebs, but the solutions are not helping me. I can’t figure out what I’m doing wrong here. It’s a very common problem, but I seem to have the code right, right?
This is my code (the usefull part, anyway):
<script>
$(document).ready(function(e) {
$("#editdialog").dialog({
autoOpen: false,
width: 400,
height: 600,
});
$(".editfreight").one("click", function(){
$("#editdialog").load("inc/ajax/editfreight_ajax.php?id=" + $(this).data("freight"));
$("#editdialog").dialog("open");
});
});
</script>
<div id="editdialog" style="display: hidden"></div>
Well, i’m hoping someone can help me out here! I’ve also tried this:
$(".editfreight").one("click", function(){
$("#editdialog").dialog({
autoOpen: false,
width: 400,
height: 600,
close: function() {
$("#editdialog").dialog("destroy")
});
$("#editdialog").load("inc/ajax/editfreight_ajax.php?id=" + $(this).data("freight"));
$("#editdialog").dialog("open");
)};
This way, I figured I initiate the dialog when I click the button (and not on pageload), and destroy the instance when I close the dialog. Apparently this isn’t working either.
The event handler attachment should be
on("click"), notone("click"),onewill only trigger oncesee
onedoc: http://api.jquery.com/one/