MAX POWER
MAX POWER

Reputation: 5448

jQuery UI Sortable - pass additional data with serialize

In the below code, I also want to pass the value listing_id in my AJAX post:

$('#listing .images').sortable({
    tolerance: 'pointer',
    update: function(event, ui){
        var data = $(this).sortable('serialize');
        var listing_id = $('#listing').attr('data-id');

        $.ajax({
            type: 'post',
            dataType: 'json',
            url: 'listings/sortimages',
            data: data,
            success: function(result){
                alert('Successfully re-ordered items.');
            }
        });
    }
});

I have tried:

data.push({name: 'listing_id', value: listing_id});

It says data.push is not a function.

Upvotes: 0

Views: 631

Answers (1)

AmmarCSE
AmmarCSE

Reputation: 30557

data.push({name: 'listing_id', value: listing_id});

doesn't work because data is a serialized string. Try

data += '&listing_id=' + listing_id;

Upvotes: 4

Related Questions