2010-07-02 68 views
0
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 

我在遗留应用程序中。我不得不进行一次修复,即IFrame需要将一个JSON包返回给parent.document。然后,在提交父文档后,数据将在服务器端提供。将隐藏字段值设置为JSON(jQuery/JavaScript)

使用alert来试图弄清楚发生了什么。我是否需要先编码JSON(之前,我把它放在了JS二号线

UPDATE:。 我看看它现在正在做它设置在像这样的DOM值

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

作品在其他浏览器但是这里有一些关于JSON.sqlify的IE文档http://msdn.microsoft.com/en-us/library/cc83645 9(V = vs.85)的.aspx – BuddyJoe 2011-06-03 19:21:12

回答

0

肯定的。否则你将设置隐藏的``c.toString(). firefox has .toSource(结果)`但是这是不可移植的。看到http://www.json.org/的一个实现。