2010-07-02 58 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/的一個實現。

相關問題