Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6231045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:51:47+00:00 2026-05-24T09:51:47+00:00

When i click my login button, it just reloads the page for some reason.

  • 0

When i click my login button, it just reloads the page for some reason. it should alert the string i echo from my php page.

This is my login.js code:

$(document).ready(function(){
    $('#login').click(function(){


        $('#msgLoginStatus').show();
        $('#msgLoginStatus').html("processing...");

        $.post('login.php',{username:"bob",password:"pass"}, function(data){
            alert(data);
        });
    });

});

my login.php:

<?php 
    echo "message";
?>

and my form:

          <form id="loginForm" action="" method="post">
             <fieldset id="body">
                        <fieldset>
                            <label for="username">Username</label>
                            <input type="text" name="username" id="username" />
                        </fieldset>
                        <fieldset>
                            <label for="password">Password</label>
                            <input type="password" name="password" id="password" />
                        </fieldset>
                        <button id="login">login</button>
                        <label for="checkbox"><input type="checkbox" id="checkbox"     />Remember me</label>
                        <br />
                        <p id="msgLoginStatus" style="display:none"></p>
                    </fieldset>
                    <span><a href="#">Forgot your password?</a></span>
                </form>

There are no errors in browser console. I tried this also using $.ajax, it returned an error, i tried putting the error variable in an alert, but when it alerted, it was an empty string. Anyone have an idea whats wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:51:48+00:00Added an answer on May 24, 2026 at 9:51 am

    Your login button has an ambiguous action – add type="submit" like this:

    <button id="login" type="submit">Login</button>
    

    Now if you really want to execute an explicit POST with JavaScript, call e.preventDefault so the browser’s automatic “submit” action will be suppressed.

    e.preventDefault();
    $.post(...);
    

    But it will probably be better to let the form submit itself. To do this specify the correct action="login.php" attribute in the form:

    <form id="loginForm" action="/login.php" method="post">
    

    Keep your existing “click” handler on the login button, just remove the “$.post” part and let the browser handle the posting. You’ll still get the nice “processing…” text.

    Even better, handle the “submit” event on the form instead of the “click” event on the button:

    $('#loginForm').submit(function(e) {
      $('#msgLoginStatus').show();
      $('#msgLoginStatus').html("processing...");
    });
    

    This way you’ll get the nice updates whether the user submits the form using the button or by pressing “enter” on the keyboard.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Example: The user login to the webpage => Click on a button This action
When you click login, it should then display the logout button. Clicking the logout
I have a Facebook Login Button on a login.php page on my website, and
I redirect the user to the login page when user click log out however
Here's the scenario I have a page lets say login.aspx having a button called
I've got to put a login page from a 3rd party website in an
I'm using Forms Authentication (and the built in Login controls) and letting users click
Click here to see what I mean.. What could prevent these two from sitting
Click on this link , you will be redirected to a shopping site. On
User click on a link button and it will direct them to a url

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.