I'm trying to do this:
$.ajax({
type: "PUT",
url: /example,
data: {_method: "put", "foo_model[bar_attribute]": value_var }
});
And works as expected but I need to construct the part foo_model[bar_attribute]dynamically.
I'm trying with:
var model = "foo_model";
var attribute = "foo_attribute";
var param = model + "[" + attribute + "]";
var dataStr = '{_method: "put",' + param + ': ' + value + '}';
and again:
$.ajax({
type: "PUT",
url: /example,
data: dataStr
});
But it doesn't work, jQuery is escaping quotes and adding curly brackets everywhere around...
Is there any better way to do this? I also tried other ways like making a json object, setting processData to false, as I saw in another post but nothing seems to be working... The request is always transformed and escaped. Also tried unescape but it only works if I write literally:
data: {_method: "put", "foo_model[bar_attribute]": value_var }
Thanks.