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.

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.

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;
};

Comments

Your Answer

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.