[jQuery] ajaxForm + jquery ui dialog + ajax won't work multiple times

[jQuery] ajaxForm + jquery ui dialog + ajax won't work multiple times


Hi i'm stuck at the following. I have made a button that puts out a
clear request for a form. The flow of this should be: dialog -> if yes
-> use ajaxForm to submit -> reload section
so in my document ready i have the following: (multiple buttons can
exist)
$(".blockClear").each(function (i) {
$(this).bind("click", function () {
var split = this.id.split("_");
var options = {
target: "#checkOutput",
url: "/index/clear",
type: "POST",
dataType: "json",
beforeSend: function (){
},
success: function () {
actions.loadsection(split[2],
"render");
}
}
$("#f" + split[0]).ajaxForm(options);
$("#f" + split[0]).submit();
});
});
The above snippet works everytime even if the section is reloaded
via ajax. So to put in a confirmation dialog I did the following. I
changed the bind so it calls a method that generates the confirmation
dialog and upon yes, does the samething as a above:
(so inside the method:)
var id = id;
var defaults = {
autoOpen: false,
resizable: false,
modal: true,
height: 180,
overlay: { backgroundColor: "#000", opacity: 0.5 },
buttons: {
"Nee" : function () {
$(this).dialog('close');
},
"Ja" : function () {
var split = id.split("_");
var options = {
target: "#checkOutput",
url: "/index/clear",
type: "POST",
dataType: "json",
beforeSend: function (){
},
success: function () {
actions.loadsection(split[2],
"render");
}
}
$("#f" + split[0]).ajaxForm(options);
$("#f" + split[0]).submit();
}
}
$('#clearDialog').dialog(defaults);
$("#clearDialog").dialog('open');
Now here's the strangest thing. The first time (on page refresh) it
works like a charm. I get the dialog push the button and away it goes,
it sends out the ajax request returns the json and reloads the
section.
When the section is reloaded via ajax, and I try pushing the button
again. I get the dialog, press the "ja" button......and nothing. It
does not submit the form again.
So to summarize, without the dialog it's all fine, with the dialog it
only works once.
Can anybody shed some light on this?
Thanks....