[ACCEPTED]-jQuery serialize an object?-serialization
Accepted answer
You should use jQuery.param()
instead.
Working Example
With vanilla JS, you 1 would use JSON.stringify
instead.
As mentioned you should use .param()
$.param({id: 1, name: "Some name", color: '#444444' })
But 3 also you need to be careful with your syntax. Your 2 brackets don't match, and that color will 1 need quotation marks. jsFiddle
You could use JSON.stringify
to serialize your object, and 1 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"}"
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.