Uncaught TypeError: Cannot read property 'appendChild' of null

后端 未结 10 2040
予麋鹿
予麋鹿 2020-12-14 08:43

I\'m getting the following error

Uncaught TypeError: Cannot read property \'appendChild\' of null

myRequest.onreadystatechange @ script.js

10条回答
  •  不思量自难忘°
    2020-12-14 09:07

    Nice answers here. I encountered the same problem, but I tried but I didn't work quite well. I had all the code and links set up fine. The problem is I had put the js file link in the head of the page, so it was loaded before the DOM was loaded. There are 2 solutions to this.

    1. Use
    window.onload = () => {
        //write your code here
    }
    
    1. Add the to the bottom of the html file so that it loads last.

提交回复
热议问题