I have a problem I can't solve by myself:
I have a function, getPerimetre()
which is supposed to return all the element's id with the class .perimetre
var getPerimetre = function () {
var perimetre = [];
$(".perimetre").each(function() {
perimetre.push($(this).attr("id"));
});
return perimetre;
};
Problem is I want to execute this function after an AJAX call which fills my container #prevision_form
.
var updateForm = function () {
var data = getData();
var form_request = $.ajax({
url: "lcl-flux-prevision_modification_form.php",
type: "POST",
data: data
});
form_request.fail(function(jqXHR, textStatus) { alert( "Request failed: " + textStatus ); });
form_request.done(function(html) { $("#prevision_form").html(html); });
};
So, my code gives something -synthetized- like this:
updateForm();
if(!$._data($("#saveRecord")[0], "events")) {
$j("#saveRecord").bind("click", function() {
alert(getPerimetre());
});
}
When I click my button #saveRecord
, the alert is empty.
If I put call to my function getPerimetre()
before the AJAX call, it works correctly.
Any suggestion?