JQuery not defined (JQuery is not defined) [closed]

2

There I leave the code, it explodes a couple of times and I do not understand why it does not work, before it marked an error in the if so I left it commented, after that this JQuery error appeared maybe that's why

JQuery(document).on('submit', '#lg', function(event){
    event.preventDefault();

JQuery.ajax({
 url: 'php/login.php',
 type: 'POST',
 dataType: 'json',
 data: $(this).serialize(),
 /*beforeSend: function(){
    $('.env').val('Validando...');
 }*/
})
.done(function(respuesta){
    console.log(respuesta);
    /*if(|respuesta.error){
        alert("al fin ctm!!!!");
    }else{
        $('.error').slideDown('slow');
        setTimeout(function(){
            $('.error').slideUp('slow');
        },3000);
        $('.env').val('Iniciar');
    }*/
})
.fail(function(resp){
  console.log(resp.responseText);  
})
.always(function(){
    console.log("complete");
});
});

Here I leave the HTML and PHP code

<!DOCTYPE html>
<html lang="es">
<head>
    <title></title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="css/estilosacademia.css">
    <link rel="stylesheet" href="css/login.css">
</head>
<body>
<div class="error">
    <span>asdgasdgasiujdgasijudgsuidgsijuagsduasgdiuaj</span>
</div>

<div class="container">
   <div class="container-fluid">
           <div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="text-center">Iniciar Sesión</h3>
    </div>
    <br>
    <div class="panel panel-default">
        <div class="panel-body">
        <form class="form-horizontal" id="lg" method="post">
        <div class="form-group">
            <label for="user" class="col-sm-2 control-label">Usuario</label>
            <input type="text" class="form-control" name="user" placeholder="Usuario">
        </div>
            <div class="form-group">
                <label for="pass" class="col-sm-2 control-label">Contraseña</label>
                <input type="password" class="form-control" name="pass" placeholder="Contraseña">
            </div>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <div class="checkbox">
                            <label>
                              <input type="checkbox"> Recuerdame
                            </label>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                      <button type="submit" class="env btn btn-default">Ingresar</button>
                    </div>
                </div>
        </form>
    </div>
    </div>
    <div class="panel-footer">
        <p class="text-center">¿No estas registrado?</p> <a href="registrarse.php">¡Registrate!</a>
    </div>
</div>
</div>
   </div>    
</div>
    <script src="js/jquery.js"></script>
    <script src="js/login.js"></script>
    <script src="js/bootstrap.min.js"></script>
    
    
    </body>
</html>
    <?php

require 'conexion.php';

$usuarios = $mysqli -> query("SELECT Nombre, Tipo_usuario 
                             FROM usuarios
                             WHERE Nombre = '".$_POST['user']."' AND Pass = '".$_POST['pass']."'");

if($usuarios -> num_rows == 1):
    $datos =  $usuarios->fetch_assoc();
    echo json_encode(array('error' => false, 'tipo' => $datos['Tipo_usuario']));    
else:    
    echo json_encode(array('error' => true));
endif;

$mysqli->close();


?>
    
asked by Víctor 08.07.2017 в 15:42
source

2 answers

1

I would think at first sight that it is jQuery with the J in lowercase, unless you have done the "mapping" to that word.

Also we do not know how you are defining jQuery, you should normally include something like this:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
    
answered by 08.07.2017 в 15:45
0

Try this, put your boton , your input of usuario and contraseña in which you send the data, a id this to perform search with JQUERY

Example: (This would be to add only the ids to your elements in your HTML )

 <input id="usuario" type="text" class="form-control" name="user" placeholder="Usuario">
<input id="password" type="password" class="form-control" name="pass" placeholder="Contraseña">
<button id="enviar" type="submit" class="env btn btn-default">Ingresar</button>

Then in your document JQUERY put this code.

$(document).ready(function()){
	event.preventDefault();
	var1 = $('#usuario').val(); //guardamos que tecleaste en el input de usuario
	var2 = $('#password').val(); //lo mismo que el anterior
	$('#enviar').click(function(event) {//en el evento click del boton lo enviamos al servidor para la peticion ajax
		$.ajax({
			url: 'php/login.php',
			type: 'POST',
			data: {var1, var2}, //son las variables que guardamos
			beforeSend:function(){
				console.log("Se esta procesando tu peticion");
			}
		})
		.done(function(data) {
			console.log("data");						
		})
		.fail(function() {
			console.log("error");
		})
		.always(function() {
			console.log("complete");
		});
	});

});

Obviously in your HTML you have to have referenced your file JS

Something like this:

<script src="js/jquery-3.2.1.min.js"></script> <!--Utilizar libreria JQUERY-->
<script src="js/codigo.js"></script> <!--TODO lo que utilize JQUERY deberá ser referenciado 			

Salúdos.

    
answered by 11.07.2017 в 06:06