Answer the question
In order to leave comments, you need to log in
Can't find id in DOM! extensions?
Insertion of array data from the server into the DOM of the extension, panel.html does not work:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="/main.css">
</head>
<body>
<ul class="nav__extensions">
<li><a id="main" href="">Главная</a></li>
<li><a id="vk_parse" href="">vk parse</a></li>
<li><a id="facebook_parse" href="">facebook parse</a></li>
<li><a href="">О нас</a></li>
<li><a href="">Контакты</a></li>
</ul>
<div class="items_extensions" id="items_extensions"></div>
</body>
</html>
window.onload = () => {
var requestURL = "http://mvs.com/feed/ajax";
var request = new XMLHttpRequest();
request.open('POST', requestURL)
request.responseType = 'json';
request.send()
request.onload = function() {
var superHeroes = request.response;
populateHeader(superHeroes);
}
function populateHeader(jsonObj) {
const items = document.getElementById("items_extensions")
if (items != null) {
for (var key in jsonObj) {
items.innerHTML = jsonObj[key]
console.log(jsonObj[key])
}
console.log(items)
}
}
}
{
"name": "ParserS V1",
"description": "ParserS v1",
"version": "1.0",
"manifest_version": 2,
"browser_action" : {
"default_popup": "panel.html",
"default_icon": "icon.png"
},
"permissions": [
"storage",
"activeTab"
],
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["background.js", "res_block.js"]
}
]
}
Answer the question
In order to leave comments, you need to log in
Try converting the json to an object before iterating over it with JSON.parse()
Perhaps you allowed a Russian character in the id name, this happens.
There might be something wrong with the markup. Inspect the element to see if the browser sees it correctly.
PS Did you accurately show all the code that you are using or did you accurately copy your code to paste here? Because everything seems to be right
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question