My plugin works in home page, but doesn’t work in post page

I think ajax request should point to the actual WordPress ajax handler.

You can pass the variable by localising the script:

$js_object = [
    'ajaxUrl'   => admin_url('admin-ajax.php')
];
wp_register_script('my-script', 'http://url');
wp_localize_script('my-script', 'pluginObject', $js_object);
wp_enqueue_script('my-script');

Register the ajax request into ajax hook:

function widget_ajax_request()
{
    // your stuff
}

add_action('wp_ajax_my_action', 'widget_ajax_request');
add_action('wp_ajax_nopriv_my_action', 'widget_ajax_request');

And your JS should be:

$jq.ajax({
    url: pluginObject.ajaxUrl, //from the localized object
    data: {
        action: 'my_action' //from the hook
    },
    success: function() {
        // your stuff
    }
})

Here is a tutorial: https://www.smashingmagazine.com/2011/10/how-to-use-ajax-in-wordpress/

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