One option is to use wp_add_inline_script()
to inline the action url to the page source. This can be done for example on the admin_enqueue_scripts
action.
In the example below I used admin_url()
with wp_nonce_url()
to retrieve the nonce wp-admin url and then added the query paramters to it with add_query_arg()
.
add_action( 'admin_enqueue_scripts', 'my_admin_action_url', 5 );
function my_admin_action_url() {
$actionUrl = add_query_arg([
'action' => 'duplicate_post_clone',
'post' => 30808,
], wp_nonce_url( admin_url('admin.php'), 'action' ));
wp_add_inline_script( 'jquery', "var myAdminActionUrl="{$actionUrl}";" );
}
The url should be now available in your script via the myAdminActionUrl
variable.