Jump to content
Pengcoder

PHP login page

Recommended Posts

Please help with Ajax call, when clicking login button nothing happens when it should go to mainpageloggedin.php

deano

Share this post


Link to post
Share on other sites

$("#loginform").submit(function(event){
//prevent default php processing
    event.preventDefault();
//collect user inputs
    var datatopost = $(this).serializeArray();
    console.log(datatopost);
//send them to login.php using AJAX
    $.ajax({
        url: 'login.php',
        type: "POST",
        data: datatopost,
        success: function(data){
            if(data == "success"){
                window.location('mainpageloggedin.php');
            }else{
                $("#loginmessage").html(data);
            }
        },
        error:function(){
            $("#loginmessage").html('<div class="alert alert-danger">There was an error with the Ajax Call. Please try again later1.</div>');
        }
});
});

Share this post


Link to post
Share on other sites

Have you checked the calls' headers and responses in the network tab of your browser's developer tools?

Share this post


Link to post
Share on other sites

There are 5 parts to an ajax call

  • generating the call (which you have shown us)
  • The headers sent to the server
  • the processing on the server
  • the response returned
  • the processing of the response (also shown)

All of those need to be correct.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.