I’ve got an object defined like this:
data = {name: 'durk durk durk', site_id: 123456}
And I’ve got a function that looks like this:
function(data) { jQuery.post('www.example.com/ajax', { method: 'add', data: data } )
Which would be awesome, except it’s posting like this:
data[name]: durk durk durk
data[site_id]: 123456
method: add
When what I want is it to post like this:
name: durk durk durk
site_id: 123456
method: add
So I thinks to myself, “Self, just take out that extra data and you’ll be all set and your coworkers will think how clever you are with your fancy object post”.
So I changed the function to this:
function(data) { jQuery.post('www.example.com/ajax', { method: 'add', data } )
Which failed spectacularly.
Please help me so I don’t have to cry myself to sleep tonight.
Thanks.
With the big hammer:
The elegant way: