Parse.com Login for javascript

Hi members of Stackoverflow,

I started learning javascript a couple of days ago, but was puzzled by one of the problems I ran into.

the form:

<form class="login-form" method="post" onsubmit="return tryLogin(this);">
    <h3 class="form-title">Login to your account</h3>
    <div class="alert alert-danger display-hide">
        <button class="close" data-close="alert"></button>
        <span>
             Enter any username and password.
        </span>
    </div>
    <div class="form-group">
        <!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
        <label class="control-label visible-ie8 visible-ie9">Username</label>
        <div class="input-icon">
            <i class="fa fa-user"></i>
            <input class="form-control placeholder-no-fix" type="text" autocomplete="off" placeholder="Username" name="username" id="username"/>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label visible-ie8 visible-ie9">Password</label>
        <div class="input-icon">
            <i class="fa fa-lock"></i>
            <input class="form-control placeholder-no-fix" type="password" autocomplete="off" placeholder="Password" name="password" id="password"/>
        </div>
    </div>
    <div class="form-actions">
        <label class="checkbox">
        <input type="checkbox" name="remember" value="1"/> Remember me </label>
        <button type="submit" class="btn green pull-right">
        Login <i class="m-icon-swapright m-icon-white"></i>
        </button>
    </div>
</form>

JavaScript:

<script type="text/javascript">
    jQuery(document).ready(function() {     
      App.init();
      Login.init();
    });

    function tryLogin(form) {

        var username = form.username.value;
        var password = form.password.value;

        console.log("Username: " + username + " Password: " + password);
        Parse.User.logIn(username, password, {
            success: function(user) {
                window.location.href="dashboard.html";
                //self.undelegateEvents();
                //delete self;
                alert("Sucess");
                return true;
                },
            error: function(user, error) {
                window.location.href="login.html";
                alert("Error: " + error.code + " " + error.message + username + password);
                return false;
                }
        });

    }
</script>

The problem is that when I try to log in, I get an error with 100 XMLHttpRequest error. This only happens when I enter data into the form and find the login. If I do not enter any data and without clicking on the login, he will correctly try to enter the system. If I put the username + password directly in javascript, it also works, but not through the form.

Console.log enters the correct username and password, but Parse.User.logIn (username, password) does not want to pass it ... but it works if I fill it out like this:

Parse.User.logIn("myemail@email.com", "mypassword", {....

Any help would be appreciated.

Hooray!

Edit: here is the error

XMLHttpRequest failed: {"statusText":"","status":0,"response":"","responseType":"","responseXML":null,"responseText":"","upload":{"ontimeout":null,"onprogress":null,"onloadstart":null,"onloadend":null,"onload":null,"onerror":null,"onabort":null},"withCredentials":false,"readyState":4,"timeout":0,"ontimeout":null,"onprogress":null,"onloadstart":null,"onloadend":null,"onload":null,"onerror":null,"onabort":null} 

MAMP? PS: .. .

+3
1

preventDefault , , , , , ajax, Parse.User.

event.preventDefault(); , .

<form class="login-form" method="post" onsubmit="tryLogin(this); event.preventDefault();">

jQuery

$(".login-form").submit (function(event) {
    ...
    event.preventDefault();
});
+3

All Articles