开发者

Setting Hidden Field Value to JSON (jQuery/JavaScript)

var c = [{"Id":40,"Action":null,"Card":"0484"}];
$('#hidJson', window.parent.document).val(c);
alert($('#hidJson', window.parent.document).val()); // returns [object Object]
alert($('#hidJson', window.parent.document).val()['Card'); // returns undefined

I'm in a legacy app. I have had to put in a fix where an IFrame ne开发者_如何学Goeds to get a packet of JSON back to a parent.document. Then the data will be available server-side after I submit the parent doc.

Using alert to try to figure out what is happening. Do I need to encode the JSON first ( before I set it on the 2nd line of the JS.

UPDATE: I see what it is doing now. It is setting the value in the DOM like so.

<input id="hidJson" name="hidJson" type="hidden" value="[object Object]" />


yes. otherwise you'll set the hidden to the result of ``c.toString(). firefox has.toSource()` but that's not portable. see http://www.json.org/ for an implementation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜