'POST http://localhost/wordpress/wp-admin/admin-ajax.php 400 (Bad Request)

I am new to WordPress, creating login flow I see admin-ajax.php getting invoked but it says 400(Bad Request) Below is the code

public function __construct()
        {
            add_action('login_enqueue_scripts', array($this,'sc_enqueue_script'), 10);
            add_action('wp_ajax_sc_login', array($this,'sc_login'));
            add_action('wp_ajax_nopriv_sc_login', array($this,'sc_login'));
        }

I am using external javascript to invoke ajax request

public function sc_enqueue_script()
        {
            ?>
            <style type="text/css">#login{display:none;}#sc-form {margin: 6% auto;width: 405px;}</style>
            <?php
            $sc_option = get_option('sc_option');
            $apikey = isset($sc_option["apikey"]) && !empty($sc_option["apikey"])?trim($sc_option["apikey"]):"";
            // $language = isset($sc_option["language"]) && !empty($sc_option["language"])?trim($sc_option["language"]):"en";
            
            wp_enqueue_script('sc-js', 'http://xxx/sc.bundle.js', false, SC_PLUGIN_VERSION);
            wp_enqueue_script('sc-script', SC_ROOT_URL . 'frontend/assets/js/loginForm.js', array('sc-js'), SC_PLUGIN_VERSION);
            wp_localize_script('sc-script', 'sc', array('ajax_url' => admin_url('admin-ajax.php'),              
            'apikey' => $apikey,            
            'redirect' => home_url()));
        }

loginForm.js

var data = {
                    'sc_token': payload.tokens.accessToken, // some value here
                };
                setInterval(function () {
                    jQuery.post(sc.ajax_url, data, function (resp) {
                        console.log("Response: " + resp);
                        window.location.href = sc.redirect;
                    });
                }, 2000);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source