Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

169
Visualizações
How to set up google oauth only using ajax and jquery

I am trying to use google oauth using ajax and jquery. I have no errors but when I click on login button, page refresh to current page. This makes me think, issue is with ajax. maybe I am missing a flag or field.

I want to go to google login page. and on success, i want to get user first name.

    <script type="text/javascript">
        $(document).ready(function () {
            $('.LoginGoogleC').click(function () {
                alert('start');
                $.ajax({
                    type: 'POST',
                    url: "https://accounts.google.com/o/oauth2/token",
                    contentType: 'application/x-www-form-urlencoded; charset=utf-8',
                    crossDomain: true,
                    cache: true,
                    dataType: 'json',
                    data: {
                        client_id: '0000000-18911.apps.googleusercontent.com',
                        client_secret: 'fff-eee-fff',
                        redirect_uri: 'https://localhost:44329/LoginAPI.aspx',
                        grant_type: 'authorization_code'
                    },
                    success: function (data) {
                        alert('success' + data);
                    },
                    error: function (e) {
                        alert('error' + data);
                    }
                });
                alert('done');
            }); 
        });
    </script>

I also tried using only jquery but still same thing. page refresh but no google oauth page

        var clientID = '0000000-18911.apps.googleusercontent.com';
            var redirectURL = 'https://localhost:44329/LoginAPI.aspx';
            window.location.href = 'https//accounts.google.com/o/oauth2/v2/auth?' +
                'scope=openid%20email' +
                '&response_type=token' +
                '&redirect_url=' + redirectURL +
                '&client_id=' + clientID;

button - html

    <asp:button ID="LoginGoogleB" CssClass="LoginGoogleC btn btn-lg center-block" runat="server" 
    Text="Login With Google" />
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda