Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!