following code:
// also tried function getDeletedDates()
var getDeletedDates = function()
{
var s = new Array();
$(".deleted").each(function(i, e) {
s.push($(e).attr("data-day"));
});
};
$(function()
{
$("#delete_send").click(function() {
alert("drin");
$.ajax({
url: "delete.php",
type: "POST",
data: ({deleteDates : getDeletedDates()}),
dataType: "json",
success: function(msg){
alert(msg);
},
beforeSend: function(){
alert("Lösche folgende Urlaubstage: "+ getDeletedDates().join(", "));
},
error: function(x, s, e) {
alert("Fehler: " + s);
}
}
);
});
});
But i come into beforeSend() he always says "getDeletedDates() undefined"
Why is this, i declared the function in global scope?
thanks in advance.
2 Answers 2
Your function doesn't return anything, so the result will be undefined. Change the method to return the array.
UPDATE:
When you do getDeletedDates() it is evaluated to undefined, because of the lack of return result. This is why getDeletedDates() is undefined is the error message.
1 Comment
You are calling your function, but the function is defined as a variable/pointer and doesn't return anything. The following modification should work (not tested):
function getDeletedDates()
{
var s = new Array();
$(".deleted").each(function(i, e) {
s.push($(e).attr("data-day"));
});
return s;
};