Frage

Im trying to make a sortable list with the following code:

$("#responds").sortable(function() {
    axis: 'y';
    update: function(event, ui) 
    {
        var data = $(this).sortable('serialize');
        $.ajax({
            type: 'POST',
            url: 'process.php',
            data: {position: data},
            dataType: "html",
            success: function(data) { alert("hej"); },
            error: function(xhr, ajaxOptions, thrownError) { alert(thrownError); }
        });
    }
});

But this only generates the following message:

SyntaxError: function statement requires a name


update: function(event, ui)

I can't understand why..

War es hilfreich?

Lösung

You're closing it with a semicolon. You want a comma

$("#responds").sortable({
    axis: 'y',
    update: function(event, ui) {
        var data = $(this).sortable('serialize');
        $.ajax({
            type     : 'POST',
            url      : 'process.php',
            data     : {position: data},
            dataType : "html",
            success  : function(data) { 
                alert("hej"); 
            },
            error    : function(xhr, ajaxOptions, thrownError) { 
                alert(thrownError); 
            }
        });
    }
});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top