wp_enqueue_script(‘testpage’, get_stylesheet_directory_uri() . ‘/js/testscript.js’, array(‘jquery’), ”, true);
jQuery.getJSON(“mydata.json”) will 404 because it’s actually looking at www.mysite.com/js/mydata.json and not at www.mysite.com/wp-content/themes/twentyseventeen-child/js/mydata.json
So I fixed it by just using jQuery.getJSON(“/wp-content/themes/twentyseventeen-child/js/mydata.json”) This works fine, currently.
But I’m afraid that doing so isn’t good practice? Hard coding the whole theme path like that in the JS file is bad, because that directory can change depending on installation, right? So is there some way to get the current theme path? Similar to get_stylesheet_directory_uri() in PHP? Or maybe there’s some other way entirely of doing this that would avoid this problem? Or is this no problem at all and I can just keep it like that?
Read more here:: How to get the path to current theme, but from a JS file?