James Balazs James Balazs - 1 year ago 85
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') }



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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download