tags:

views:

55

answers:

1

I need to update website login form with ajax. When visitor fails to login, message should appear without refreshing the page and when visitor can login he needs to be redirected to default.asp.

I tried doing this with the following code but no success. I did not receive any errors. Also, I am not sure if this is secure.

Thank you

    <script type="text/javascript">   
$(function() {
    var EmailAddress = $("name=EmailAddress").val();
    var Password = $("name=Password").val();

    $.ajax({
        type: "POST",
        url: "signin.cs.asp",
        data: 'EmailAddress='+ EmailAddress + '&Password=' + Password,
        success: function() {
        $('#contact_form').html("<div id='message'>success</div>");
        }

    });

});
    </script>
+1  A: 

The code, as posted, has several syntax errors which might be going unnoticed:

  • missing a closing brace for the success callback
  • extra semi-colon at the end of the data line

You may also pass your data in key/value format, and allow jQuery to build the query string for you:

...
data: { EmailAddress : EmailAddress, Password : Password }
...

As far as security goes, you're posting the plain text username and password to the server, which is fundamentally insecure. If you have an SSL certificate, modify your url to use https://&lt;yourdomain&gt;/signin.cs.asp

meagar
Not I get the following error.Error: syntax errorSource File: Line: 2Source Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
zurna
It sounds like an HTML document is being evaluated as Javascript; Your .js files shouldn't have doctype declarations in them. Possibly a page being included via a `<script src="...">` tag is outputting HTML instead of the JS you're expecting.
meagar