简体   繁体   中英

jquery ajax not passing parameters

I've used ajax before, but this time the ajax is not passing the parameters, I've already tried some solutions, but can't solve this.

jQuery

 $('.entrar').click(function(){
        event.preventDefault();
        if (check_login()){

            var dataLogin;
            var manter_ligado;

            if ($('#mantem_login').is(':checked'))
            {
                manter_ligado = "1";
            } else {
                manter_ligado = "0";
            }

            dataLogin = 'mail=' + $('#login_mail').val() + '&pass=' + $('#login_password').val() + '&on=' + manter_ligado;

            $.ajax({
                  url: 'modules/login.php',
                  type: 'POST',
                  //data: dataLogin,
                  data : ({
                            mail : $('#login_mail').val(),
                            pass : $('#login_password').val(),
                            on : manter_ligado
                         }),
                  success: function(data) {
                    alert('Login efectuado com sucesso.');
                    console.log(data);
                  },
                  error: function(xhr, textStatus, errorThrown) {
                    alert('Login nao entrou');
                    console.log(xhr.statusText);
                    console.log(textStatus);
                    console.log(error);
                  }
                });

            return false;

        }

    })

this is HTML

        <span class="title">Entrar na sua conta</span>

        <input name="login_mail" placeholder=" e-mail" id="login_mail" type="email" class="email text_box"/>
        <input name="login_password" placeholder="password" id="login_password" type="password" class="password text_box" />
        <span>Perdeu a password?</span>

        <div class="mantem_login">
            <input name="mantem_login" id="mantem_login" type="checkbox" class="mantem_login" />
            <label for="mantem_login"><span class="mantem_login">Manter-me conectado</span></label>
        </div>


        <input type="submit" name="entrar" class="submit_button entrar" id="entrar" value=""  />

    </div>
</form>

What can I do so that the parameters get to the url?

Remove the round brackets from your parameter value:

data: {
    mail : $('#login_mail').val(),
    pass : $('#login_password').val(),
    on : manter_ligado
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM