WordPress add_query_arg from ajax and make url friendly

This add_query_arg function is add argument after URL you have enter.

You have to get pretty URL so add below code in your functions.php file :

function custom_rewrite_rule() {
    add_rewrite_rule('^cars/([^/]*)/([^/]*)/?','index.php?page_id=PAGE_ID&type=$matches[1]&models=$matches[2]','top');
    flush_rewrite_rules();
}
add_action('init', 'custom_rewrite_rule', 10, 0);

function custom_rewrite_tag() {
  add_rewrite_tag('%type%', '([^&]+)');
  add_rewrite_tag('%models%', '([^&]+)');
}
add_action('init', 'custom_rewrite_tag', 10, 0);


add_action( 'wp_ajax_get_prepare_link', 'prepare_link');
add_action( 'wp_ajax_nopriv_get_prepare_link', 'prepare_link');
function prepare_link() {

    $url = "";
    $url .= get_the_permalink( PAGE_ID );
    $url .= "compare/aaa-and-bbb-and-ccc"

    echo $url;
    wp_die();
}

In above code replace “PAGE_ID” with your “car” page id.