javascript - Uncaught TypeError: Cannot read property 'length' of null JSON-JQUERY -
There are problems with its function and show uncut type error for the console: the 'length' of the property can not be read and Why not
function shownAMEplaylist () {$ .getJSON ("js / json / nameplaylist.json", function (data) {var items = []; $ .each (data, function ( Key, value) {$ ('Nameplaylist'). Append ('& lt; option & gt;' + value.title + '& lt; / option & gt;'}}); $ (' First-child '). Attr ("selected", "selected"); name playlist = $ (".nameplaylist option: selected") .text (); console.log (nameplaylist.l Ength); if (nameplaylist.length == 0) {$ ('#nameplaylist'). Css ('display', 'none'); $ ('# delplaylist'). CSS ('display', 'none ')}}}. Done (function () {// If an error show playlist has arrived in AJAX call);}) .fail (function () {// If any error in AJAX call console.log (' no Load nameplaylist '); $ (' #nameplaylist '). CSS (' Display ',' None '); $ (' # DanielList '). CSS (' Display ',' None '); $ ('#delplaylist') CSS ('display', 'none');); You are using two different selectors for "nameplaylist",
And .nameplaylist First of an "nameplaylist" means an element with a id and second, with the class of "nameplaylist" One element implies. $ ('#nameplaylist') and $ ('.nameplaylist') will not select the same element unless both of your elements id and "Nameplaylist" class : & Lt ;! - $ ('# nameplaylist') - & gt; & Lt; Elem class = "name playlist" /> & Lt ;! - $ ('.nameplaylist') - & gt; Decide how you are actually using and can modify your selectors accordingly.
By looking at your code, I think your fix bus line 7 and 8 per:
$ ('#nameplaylist option: first-child'). Ether ("selected", "selected"); Nameplaylist = $ ("#nameplaylist Options: Selected") .text ();
Comments
Post a Comment