Haciendo pruebas llega la información al PHP pero no retorna nada al script.
index.html
Código HTML :
<script type="text/javascript" src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function(){
$('form').submit(function(){
$.post('ajax.php',$(this).serialize(),
function(data){
if(data.success == true)
{
alert(data.success);
location.href=data.redirect;
}
else
{
alert(data.success);
$('#errorConsole').html(data.message);
}
}, 'json');
});
});
</script>
<div id="errorConsole"></div>
<form method="post" name="loginForm">
Username:<br/>
<input type="text" name="username"/><br/>
Password:<br/>
<input type="password" name="password"/><br/>
<input type="submit" value="Login"/>
</form>
ajax.php
Código PHP :
<?php
if($_POST['username'] == 'test' && $_POST['password'] == 'test'){
$data['success'] = true;
$data['redirect'] = 'next.php';
}
else
{
$data['success'] = false;
$data['message'] = 'No puedes entrar amigo! desde AJAX';
}
echo json_encode($data);
?> 