Say I have something like:
var obj = {id: 1, name: "Some name", color: "#444444" };
I want to serialize that object. I tried:
$(obj).serialize();
but that didn't work.
Any ideas?
Say I have something like:
var obj = {id: 1, name: "Some name", color: "#444444" };
I want to serialize that object. I tried:
$(obj).serialize();
but that didn't work.
Any ideas?
You should use jQuery.param()
instead.
With vanilla JS, you would use JSON.stringify
instead.
You could use JSON.stringify
to serialize your object, and you'd have to wrap your color string correctly:
var obj = {id: 1, name: "Some name", color: '#444444' };
var serialized = JSON.stringify(obj);
// => "{"id":1,"name":"Some name","color":"#444444"}"