Note that there are some explanatory texts on larger screens.

plurals
  1. POJson data passing between html pages
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/11622324/javascript-dom-errors">Javascript DOM errors</a> </p> </blockquote> <p>I have my following html code </p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="1" "display:block"&gt; &lt;/div&gt; &lt;div id="2" "display:none"&gt; // no onLoad() anymore!! &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>My Javascript code is as follows</p> <pre><code>$.ajax({ type: 'GET', url: ........, dataType: "json", complete: function (xhr, statusText) { alert(xhr.status); }, success: function (data, textStatus, jqXHR) { alert(JSON.stringify(data)); if(document.getElementById(1).style.display == "block"){ document.getElementById(1).style.display = "none"; document.getElementById(2).style.display = "block"; } addBooks(data); // Passing JSON to be replaced on page }, function (data, textStatus, jqXHR) { alert(data); alert('error'); }, }); function addBooks(data) { // USing DOM to populate the tables //var newdata=document.getElementById('addBooks'); //newdata.setattribute() //get the unordered list var newdata = document.getElementById('addBooks'); var parent = document.getElementById('gBookList'); //removeChildrenFromNode(parent); //create list divider var listdiv = document.createElement('li'); listdiv.setAttribute('id', 'gBookListDiv'); listdiv.innerHTML = ("Books Found:"); parent.appendChild(listdiv); // (this is where the first error happens) //create dynamic list for (i = 0; i &lt; data.length; i++) { // (this is where the second error happens) //create each list item var listItem = document.createElement('li'); listItem.setAttribute('id', 'gBookListItem'); parent.appendChild(listItem); //var link = document.createElement('a'); //link.setAttribute('onclick','displayBook(data[i])'); //link.setAttribute('href','#FindBook)'); //listItem.appendChild(link); var pic = document.createElement('img'); pic.setAttribute('src', data[i].pictureURL); pic.setAttribute('width', '80px'); pic.setAttribute('height', '100px'); pic.setAttribute('style', 'padding-left: 10px'); link.appendChild(pic); var brk = document.createElement('br') link.appendChild(brk); var title = document.createElement('p'); title.innerHTML = data[i].title; title.setAttribute = ('style', 'float:right'); link.appendChild(title); var author = document.createElement('p'); author.innerHTML = data[i].author; link.appendChild(author); } var list = document.getElementById('gBookList'); // $(list).listview("refresh"); } /*function removeChildrenFromNode(node){ while (node.hasChildNodes()){ node.removeChild(node.firstChild); } //}*/ </code></pre> <p>I keep getting the following error which prevents me from populating the list , I am using chrome</p> <p>1) Uncaught TypeError: Cannot call method 'appendChild' of null 2) Uncaught TypeError: Cannot read property 'length' of undefined</p> <p>I have posted this question yesterday , but I just wanted a fresh perspective on what the error could be </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload