How can I access custom data fetched from posts in a javascript script?

The best practice way would be to create a REST API endpoint using register_rest_route() hooked to rest_api_init that your Javascript can query.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)