JQuery function not found

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 enter beforeSend (), it always says " getDeletedDates () undefined" Why is this, I declared a function in the global scope?

early.

+4
source share
2 answers

Your function returns nothing, so the result will be undefined. Modify the method to return an array.

UPDATE

When you execute getDeletedDates() , it evaluates to undefined due to lack of return result. This is why getDeletedDates() is undefined is an error message.

+5
source

You call your function, but the function is defined as a variable / pointer and returns nothing. The following modification should work (not verified):

 function getDeletedDates() { var s = new Array(); $(".deleted").each(function(i, e) { s.push($(e).attr("data-day")); }); return s; }; 
+2
source

Source: https://habr.com/ru/post/1316385/


All Articles