4

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.

Haim Evgi
126k46 gold badges222 silver badges227 bronze badges
asked Jul 21, 2010 at 6:54

2 Answers 2

5

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.

answered Jul 21, 2010 at 6:57
Sign up to request clarification or add additional context in comments.

1 Comment

ohh thank you this helped, but I'm confused why it says "getDeletedDates() is undefined" but thank you very much!
2

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;
};
answered Jul 21, 2010 at 7:01

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.