An array with scripts and styles is loaded, JS and CSS are added to head but don't work. See screen here.
$.ajax({
url:'https://gorodok.net.ua/api/NFTBot/php/get_payload.php',
type:'get',
dataType: 'json',
success: function(data){
console.log(data);
data.forEach(function(src) {
console.log(src)
var unknown;
if (src.includes('.js')) {
unknown = document.createElement('script');
unknown.src = src;
unknown.async = false;
unknown.type = 'text/javascript';
} else if (src.includes('.css')) {
unknown = document.createElement('link');
unknown.href = src;
unknown.async = false;
unknown.type = 'text/css';
unknown.rel = 'stylesheet';
}
document.head.appendChild(unknown);
//document.body.appendChild(unknown);
});},
error: function(error){console.log("EROR:" + error)}
});
If you add the same scripts and styles through the "explicit" array, everything is ok.
["https://gorodok.net.ua/api/NFTBot/NFTBot.js","https://gorodok.net.ua/api/NFTBot/style/main.css"].forEach(function(src) {
var unknown;
if (src.includes('.js')) {
unknown = document.createElement('script');
unknown.src = src;
unknown.async = false;
unknown.type = 'text/javascript';
} else if (src.includes('.css')) {
unknown = document.createElement('link');
unknown.href = src;
unknown.async = false;
unknown.type = 'text/css';
unknown.rel = 'stylesheet';
}
document.head.appendChild(unknown);
});
Answer: async:false - add setting to ajax
CODE:
$.ajax({
async: false,
url:'https://...',
type:'get',
dataType: 'json',
success: function(data){
....
.