James Balazs James Balazs - 3 months ago 13
Javascript Question

How do you merge two jquery posts into one in coffeescript?

I need to merge these two objects:

{ swim_lane_id: $(this).closest('ul').data('lane-id') }


+

$(this).sortable('serialize')


into one object that can be sent as the [DATA] in a $.post:

$.post($(this).data('update-url'), [DATA] );


$.merge only gives swim_lane_id and an id that is part of the update-url data tag but doesn't give the serialized data from the sortable list.

I basically need to be able to pass these through in one post because the update-url data tag routes to a controller action in my Rails application and I need to know which list is being updated for every update action sent to it.

Answer

Well that looks simple enough :

$.post $(this).data('update-url'),
    swim_lane_id : $(this).closest('ul').data('lane-id')
    some_other_name : $(this).sortable('serialize')

You're passing the two properties in one object.

Comments