Reputation: 283
Have some JavaScript that assigns values to an object using $.data
and then uses JSON.stringify
. It was working in 1.4.4 (got actual JSON data) but it is broken in 1.5.2+ (empty data).
What am I doing wrong?
$document.ready {
var o;
o = {};
$(o).data("to","[email protected]");
$(o).data("from","[email protected]");
$(o).data("html","true");
$('#log').append(JSON.stringify(o));
};
<div id="log" class="line1"></div>
Can be reproduced here: http://jsfiddle.net/Km4M4/6/
Upvotes: 0
Views: 491
Reputation: 1520
$.data is used to store "programmable attributes" in any html tag. These values are not mented to be serializable. Other case is an object (your case) you want to serialize attributes. Try doing @Mrchief or the more js oriented below
var o = {
a: 'some data',
b: 'more data'
};
o.foo = bar;
$('#div').text( JSON.stringify(o) );
See in this approach there's no need to use quotes because JSON.stringify puts there for you ;)
Upvotes: 0
Reputation: 76248
Your jsfiddle doesn't have the JSON library included. Also, you're invoking jQuery ready the wrong way.
But any reason why you cannot define it like this:
o = {
"to":"[email protected]",
"from":"[email protected]",
"html":"true"
};
Updated working fiddle: http://jsfiddle.net/Km4M4/8/
Upvotes: 1