开发者

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);
        开发者_Go百科          }
               }
            );
        });
    });

But i come into beforeSend() he always says "getDeletedDates() undefined" Why is this, i declared the function in global scope?

thanks in advance.


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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜