現在JSON數據已存儲在ajax中的變量「msg」中。我只能在頁面中提醒(msg)。但我想把它放入數據表或以任何合適的方式查看ajax或js中的列的數據。將json轉換爲jQuery數據表中的ajax?
這裏是JSON類型:
{ "aaData": [ { "ID": "1", "FESTIVAL": "Antipodes Festival", "SUBURB": "Lonsdale Street, Melbourne", "POSTCODE": "3000", "WEBSITE": "http://www.antipodesfestival.com.au/", "DESCRIPTION": "The greek precinct in melbourne cbd will transform into a huge, free street festival with the hosting of the antipodes lonsdale street festival which will hold sway from 14 february 2015 to 15 february 2015." }, { "ID": "5", "FESTIVAL": "Boite Singers Festival", "SUBURB": "Victoria", "POSTCODE": "3000", "WEBSITE": "http://boite.com.au/index.php", "DESCRIPTION": "The boite singers festival brings you four days of vocal inspiration and sheer fun on the second weekend of january each year." } ] }
它給出了一個錯誤:0x800a138f - JavaScript運行時錯誤:無法獲取未定義或空引用的屬性「長度」。發生在myjson.aaData.length中。順便說一句,我已經在頁面中添加了參考,我不知道爲什麼。 –
我試過你的代碼,它的工作原理。唯一的問題是我的數據存儲在變量「msg」中,每當我從sql server獲取數據時它都會更改(但格式相同)。我不能var myjson = {...};我用msg.aaData.length,它會給上面的錯誤。你能告訴我如何解決它嗎? –
它在創建dataTable()時會產生錯誤。 –