Buenas noches,
creo que es una pregunta simple pero quizá por la hora que es no encuentro porque me falla Ajax en el login de usuarios:
Mi formulario:
<form id="form-validation" name="form-validation">
<div class="form-group">
<input id="validation-email"
class="form-control"
placeholder="Nombre de usuario"
name="login-username"
type="text"
data-validation="El usuario introducido no es válido">
</div>
<div class="form-group">
<input id="validation-password"
class="form-control password"
name="login-password"
type="password" data-validation=""
data-validation-message="Contraseña incorrecta"
placeholder="Contraseña">
</div>
<div class="form-group">
<div class="checkbox">
<label>
<input type="checkbox" name="remember" checked>
Recordar
</label>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary width-150">Iniciar Sesión</button>
</div>
</form>
Ajax:
$(document).ready(function(){
$(".form-actions > .btn").click(function(e){
alert($("#form-validation").serialize());
var base_url = $('#htmlbaseurl').text();
$.ajax({
type: 'POST',
url: base_url + 'Pages/checklogin',
data: $("#form-validation").serialize(),
success:function(e){
alert("funciono");
},
error:function(e){
alert("error");
}
});
});
});
Mi controlador Codeigniter
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Pages extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->database();
$this->load->helper('url');
$this->load->library('tank_auth');
}
public function view($page = 'home')
{
if ( ! file_exists(APPPATH.'views/pages/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
show_404();
}
$data['title'] = ucfirst($page); // Capitalize the first letter
$data['base_url'] = base_url();
$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);
}
public function checklogin(){
$email = $_POST['login-username'];
$passwd = $_POST['login-password'];
$query = $this->db->select('id')->from('users')->where('username', $email)->where('password', $passwd)->get();
if($query->num_rows() > 0){
setcookie('c_pr_user2', $query->row()->userId, time()+(86400*30), '/');
redirect(base_url().'');
}
else{
echo 'Error credenciales';
}
}
}
base_url
? Me parece que ese es el problema.