0

I have the following script:

$('#login-box .forgot-pwd').click(function (e) {
        e.preventDefault();
        $('#login-box #main-login').hide("fast");
        $('#login-box .login-error').hide();
        $('#login-box #forgot-login').show("fast");
        $('#forgot-username').focus();
        $('#login-box .forgot-send').click(function (e) {
            e.preventDefault();
            $.ajax({
                url: '/login.php',
                data: $('#login-box form.get-password').serialize() + '&action=forgot',
                type: 'POST',
                success: function(html) {
                    if (html == 'success') {
                        $('#login-box #forgot-login').hide("fast");
                        $('#login-box').append('<p>Your password has been emailed to you</p>');
                        $('#mask , .login-popup').delay(1500).fadeOut(300 , function() {
                            $('#mask').remove();
                        });
                    } else {
                        $('#login-box .login-error').show("fast");
                    }
                }
            });
        });
    });

For forgotten password. The PHP is:

$email = trim($_POST['forgot-username']);

    $objcustomer = new customer;
    $objcustomer->get_pwd($email);

    $cust_auth=$objcustomer->password;

    if (!empty($cust_auth)) {

        $to=$email;
        $from='......';

        $subject = '......';
        $headers = "From: ......\r\n";
        $headers.= "Reply-To: $from\r\n";
        $headers.= 'Content-type: text/plain;charset="iso-8859-1"';

        $message="Your ...... password is:\n\n" .
                 "$cust_auth\n\n" .
                 "Please return to ...... and login to continue your order.";

        mail($to, $subject, $message, $headers);

        echo 'success';

    } else {

        echo 'fail';

    }

The problem is that on success, the email is sent but the modal box shows the error text, not the success text so I am presuming I am missing something in getting and reading whether the script was successful and I can't work out what.

Can anyone help please?

Edited by simplypixie

3
Contributors
11
Replies
12
Views
5 Years
Discussion Span
Last Post by simplypixie
0

What is the response you see when you log the response? Check the response in firefox using firebug or chrome's development tool. My guess is, the mail function probably returns some value which adds another response to the 'success'.

0

I have logged to console and I get the correct html 'success'. I have also tried the other way around (checking for fail first) and the same happens but the other way around - i.e. I get the success message instead of the fail message, again the log to the console shows the correct html of 'fail'.

For some reason my if else statement doesn't seem to be working as it should even with the correct data being sent through to it.

0

No it doesn't. Plus if I make it fail with an incorrect email address I am getting the correct HTML in the console so the PHP part is working as it should and sending the correct data back into the Ajax request as it should but then the if else is failing in the jQuery/Ajax.

0

I am not seeing that (using Console in Chrome or firebug in Firefox)??? How are you seeing that please?

0

Using IE9 developer tools. Perhaps trimming it before the check will fix it then.

Edited by pritaeas

0

I think pritaeas suggestion of trimming might work. You could also try returning a json encoded format rather than a html response for a better convention.

0

Thank you so much pritaeas, I have used trim and all is now working as it should.

lambing - I haven't got my head around json yet but will consider in the future, thank you.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.