You can use the wp_localize_script() for the frontend when registering the javascript for the frontend. Take a look to the below example.
Open the functions.php file and paste the following codes.
function wp77934_enqueue_scripts() {
wp_enqueue_script( 'ajax-script', get_template_directory_uri() . '/js/signin-script.js', array('jquery') );
wp_localize_script(
'ajax-script',
'OBJ',
array( 'ajax_url' => admin_url( 'admin-ajax.php' ) )
);
}
add_action( 'wp_enqueue_scripts', 'wp77934_enqueue_scripts' );
Now use the OBJ global object in your javascript file.
// signin-script.js file
jQuery.ajax({
type: "POST",
dataType: "json",
url: OBJ.ajaxurl,
data: formData,
success: function(response){
console.log(response);
}
});