Jump to content

Question about a redirection with jQuery


ericblanc

Recommended Posts

Hi, here's my problem, i've built a login form which is using jquery validation. The jQuery function calls a php file (with ajax), the php file check if the member exists and it returns an echo if the login is successfull or not. The problem is that now I don't want to make an echo but more like a Header: Location (redirection). My page doesn't load complety, in fact, only the bottom part is redirecting.

 

loginform.html

<script type="text/javascript"  charset="utf-8">
    jQuery(function() {
        // show a simple loading indicator
        var loader = jQuery('<div id="loader"><img src="images/loading.gif" alt="loading..." /></div>')
            .css({position: "relative", top: "1em", left: "25em"})
            .appendTo("body")
            .hide();
        jQuery().ajaxStart(function() {
            loader.show();
        }).ajaxStop(function() {
            loader.hide();
        }).ajaxError(function(a, b, e) {
            throw e;
        });
       
        jQuery("#form").validate({
            submitHandler: function(form) {
                jQuery(form).ajaxSubmit({
                    target: "#result"
                });
            },
           
            rules: {
            user: {
                required: true,
                email: true
            }
        },
        messages: {
            user: "Veuillez entrer un courriel valide"
        }
        });
    });
</script>

</head>
<body>

<h1 id="banner">Module Membre</h1>
<div id="main">

<form method="post" class="cmxform" id="form" action="formloginmember.php">
    <fieldset>
        <legend>Connexion</legend>
        <p>
            <label for="user">Courriel</label>
            <input id="user" name="user" class="required"/>
        </p>
        <p>
            <label for="pass">Password</label>
            <input type="password" name="password" id="password" class="required" minlength"5" />
        </p>
        <p>
            <input class="submit" type="submit" value="Login"/>
        </p>
    </fieldset>
    <input type="hidden" name="type" value="profile">
</form>

<div id="result"></div>

 

 

formloginmember.php

<?php
session_start();
ob_start();
include("config.php");
usleep(500000);
$MemberEmail = $_REQUEST['user'];
$MemberPassword = md5($_REQUEST['password']);
$LoginType = $_REQUEST['type'];

$r = connectMember($MemberEmail, $MemberPassword);
if ($r == 1)
{
    echo "<font color=green>Connexion rèussi</font>";
}
else
{
    echo "<font color=red>Échec de connexion</font>";
}
if ($LoginType == "profile")
{
    header("Location: index.html");
}

 

Thanks !

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.