Reputation: 1524
I have a javascript hash (object?) we will call settings_hash
that basically looks like this:
{ setting_1=90, setting_2=30, setting_3=19 }
And I've got a post that looks like this:
jQuery.getJSON("model/queries.cfc", {
method: 'methodName',
data: jQuery.param(settings_hash),
}, function(data){
// callback stuff goes here
}
);
I really don't like having to decode the data string on my queries page (it's coldfusion- bleah). Is there an easy way to handle the decode a little better on the client side? So that what we functionally get is this:
jQuery.getJSON("model/queries.cfc", {
method: 'methodName',
setting1: 90,
setting2: 30,
setting2: 19,
}, function(data){
// callback stuff goes here
}
);
Obviously if .serialize() or .param() is the way to go, then that's fine. What I want to avoid is a big long string that I have to decode, like data=setting_1%3D90%26setting2%3D30%26setting3%3D19
. Open to all solutions/feedback- if the big long string is really the way to go for some reason, convince me and you'll get credit for the answer!
Upvotes: 1
Views: 2133
Reputation: 12730
Your "hash" isn't a valid JavaScript object literal that can be serialized into JSON.
Convert from what you have to simply using an actualy JS object literal, like this:
var data = {
method: 'methodName',
setting1: 90,
setting2: 30,
setting2: 19
}
Then just pass to your AJAX call, no manual serialization necessary:
jQuery.post(url, data, callback);
function callback(d) {
//stuff
}
Upvotes: 1