javascript - Html table row not appending to specified table -
I am trying to add json string to an HTML table. I object data is correct but this table is not attached to me
GetSongs (id) {$ .ajax ({type: "go", url: "@ Url.Action (" GetSongs ",). "Play"), "data: {playlistId: id}, success: work (data) for {json = data; obj = JSON.parse (json); (var i = 0; i & lt; data.length; I ++) {$ ('# song-table'). Endend ('& lt; tr & gt;' + htmlEncode (obj [i]. Song URL) '' ')}} }}); } HTML table:
& lt; Div id = "player-playlist" & gt; & Lt; Table id = "song-table" style = "width: 420px" & gt; & Lt; TR & gt; & Lt; Th & gt; Song & lt; / Th & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; Http: //www.youtube.com/v/CFF0mV24WCY< / TD & gt; & Lt; / TR & gt; & Lt; / Table & gt; & Lt; / Div & gt;
delete htmlEncode () because it is not defined by your JS, define or remove it for (var i in obj) {$ ("# song-table"). Annexe (" Tt>" + obj [I]. + Songral + " "); } {$ ("# Song-table") for or (in obj me i) Attached ("& lt; tr> " + htmlEncode (obj [i]. Song URL + " "); } Function htmlEncode (string) {var pre = document.createElement ('pre'); Var text = document.createTextNode (string); Pre.appendChild (text); Before return. HIL; } // and HTML avoids this encoding HTML
Comments
Post a Comment