How to enqueue or include json file to a plugin

I have a file called settings.html that include two files in the footer which are a javascript file and a json file.

<script src=”script.js”></script>
<script src=”settings.json”></script>

Basically, my javascript file needs the json file to work properly.

In my plugin.php file I enqueued my javascript file as well as my json file like this.
I know how to enqueue a javascript but not a json file so I tried something like that.

function enqueue() {
wp_enqueue_script( ‘json_settings’, plugins_url(‘settings.json’, FILE,true) );
wp_enqueue_script( ‘js_script’, plugins_url(‘script.js’,array(‘json_settings’) ,FILE),true );
}
add_action( ‘admin_enqueue_scripts’, ‘enqueue’ );

The problem here is that my javascript file works but without the json file. My javascript file cannot reach the datas inside the json file.

Read more here:: How to enqueue or include json file to a plugin

Leave a Reply

Your email address will not be published. Required fields are marked *