Jquery.each () with $ .get ()
Basically I am trying to check html values based on .home-val-icons Get these values, create path and output svg code based on the created path.
//Loops through each element
//Gets html contents
//Creates a path based on location.origin and html contents
$('.home-nav-icons').each(function() {
var counter = 0;
var select = $(this).html();
var loc = location.origin;
var findIcon = loc+"/wp-content/themes/Proxy-Engine/assets/icons/svg/"+select+".svg";
console.log(findIcon);
//Gets svg based on path,
//loops through data objects
$.get(findIcon, function(data, counter) {
$.each(data, function(counter) {
var svgData = data[counter];
$('.home-nav').append(svgData);
});
counter++;
});
});
Console error:
Uncaught SecurityError: Could not read cookie property in Document: Denied for this document.
+3
source to share
1 answer
If it's in Chrome, it might be a bug. Perhaps you can avoid this with
(function(cookie, localStorage) {
$('.home-nav-icons').each(function() {
var counter = 0;
var select = $(this).html();
var loc = location.origin;
var findIcon = loc+"/wp-content/themes/Proxy-Engine/assets/icons/svg/"+select+".svg";
console.log(findIcon);
$.get(findIcon, function(data, counter) {
$.each(data, function(counter) {
var svgData = data[counter];
$('.home-nav').append(svgData);
});
counter++;
});
}(cookie, localStorage));
So the main thing is to wrap it with a wrapper of functions
(function(cookie, localStorage) {...code...} (cookie, localStorage));
But I guess this is not the place of this error. Therefore, you need to use a wrapper in a different area. Maybe try it with all the code.
0
source to share