Login with ajax jquery
I have a problem with a simple login with ajax, apparently all is right, but I don´t know what is wrong, because I need to send a message to the client indicating that the user info is right and then redirect to main page.
Source Code
<!DOCTYPE html>
<html lang="es" >
<head>
<meta http-equiv='Content-type' content='text/html; charset=<? echo APP_CHARSET ?>' />
<title>Red Social Basica</title>
<? Tag::css('reset') ?>
<? Tag::css('design') ?>
<? echo Html::includeCss() ?>
<? echo Tag::js('jquery/jquery.min') ?>
</head>
<body class="fondobody">
<header class="topbar">
<a href="" class="bntesatico" id="lnklogin">Login</a>
<div id="dvlogeo">
User/Email<input type="text" id="txtusremail"/>
Password<input type="password" id="txtpassword"/>
<a href="" id="lnkenter">Enter</a>
</div>
<a href="" class="bntesatico" id="lnkregistro">Sign up</a>
</header>
</body>
</html>
<script type="text/javascript">
$(document).ready(function(){
$('#lnklogin').click(function() {
$('#dvlogeo').fadeToggle(200, function() {
var divID = $('#dvlistipopubs');
var openDiv = $(this).is(':visible') ? divID : null;
});
return false;
});
$('#lnkenter').click(function() {
var usremail=$('#txtusremail').val(),
password=$('#txtpassword').val();
$.ajax({
type: 'POST',
url: "account/login.php",
data: 'usremail=' + usremail +
'&password=' + password,
success: function(data) {
if(data=='ok'){
document.location="account/main.php"
}else{
alert('Access denied');
}
}
});
return false;
});
});
</script>
I used firebug to verify the answer from the server and is printing 'ok' if user and password are right and error if something is wrong, the problem is that is not working here
success: function(data) {
if(data=='ok'){
document.location="account/main.php"
}else{
alert('Access denied');
}
}
jquery ajax login
|
show 2 more comments
I have a problem with a simple login with ajax, apparently all is right, but I don´t know what is wrong, because I need to send a message to the client indicating that the user info is right and then redirect to main page.
Source Code
<!DOCTYPE html>
<html lang="es" >
<head>
<meta http-equiv='Content-type' content='text/html; charset=<? echo APP_CHARSET ?>' />
<title>Red Social Basica</title>
<? Tag::css('reset') ?>
<? Tag::css('design') ?>
<? echo Html::includeCss() ?>
<? echo Tag::js('jquery/jquery.min') ?>
</head>
<body class="fondobody">
<header class="topbar">
<a href="" class="bntesatico" id="lnklogin">Login</a>
<div id="dvlogeo">
User/Email<input type="text" id="txtusremail"/>
Password<input type="password" id="txtpassword"/>
<a href="" id="lnkenter">Enter</a>
</div>
<a href="" class="bntesatico" id="lnkregistro">Sign up</a>
</header>
</body>
</html>
<script type="text/javascript">
$(document).ready(function(){
$('#lnklogin').click(function() {
$('#dvlogeo').fadeToggle(200, function() {
var divID = $('#dvlistipopubs');
var openDiv = $(this).is(':visible') ? divID : null;
});
return false;
});
$('#lnkenter').click(function() {
var usremail=$('#txtusremail').val(),
password=$('#txtpassword').val();
$.ajax({
type: 'POST',
url: "account/login.php",
data: 'usremail=' + usremail +
'&password=' + password,
success: function(data) {
if(data=='ok'){
document.location="account/main.php"
}else{
alert('Access denied');
}
}
});
return false;
});
});
</script>
I used firebug to verify the answer from the server and is printing 'ok' if user and password are right and error if something is wrong, the problem is that is not working here
success: function(data) {
if(data=='ok'){
document.location="account/main.php"
}else{
alert('Access denied');
}
}
jquery ajax login
can you show your php file?
– Drixson Oseña
Nov 28 '13 at 15:11
2
what doesconsole.log(data)returns?, before if(data==....
– Cyrus
Nov 28 '13 at 15:12
Doessuccesseven trigger? If the response is not a200 OK, onlycompletewill trigger, notsuccess. Firebug has a Network tab. Check that for the response.
– Rudie
Nov 28 '13 at 15:31
Here is my php file, is a method because I am using MVC -> kupaste.com/ver/64167
– Alexander Ceballos
Nov 28 '13 at 15:32
The response is 200 OK
– Alexander Ceballos
Nov 28 '13 at 15:34
|
show 2 more comments
I have a problem with a simple login with ajax, apparently all is right, but I don´t know what is wrong, because I need to send a message to the client indicating that the user info is right and then redirect to main page.
Source Code
<!DOCTYPE html>
<html lang="es" >
<head>
<meta http-equiv='Content-type' content='text/html; charset=<? echo APP_CHARSET ?>' />
<title>Red Social Basica</title>
<? Tag::css('reset') ?>
<? Tag::css('design') ?>
<? echo Html::includeCss() ?>
<? echo Tag::js('jquery/jquery.min') ?>
</head>
<body class="fondobody">
<header class="topbar">
<a href="" class="bntesatico" id="lnklogin">Login</a>
<div id="dvlogeo">
User/Email<input type="text" id="txtusremail"/>
Password<input type="password" id="txtpassword"/>
<a href="" id="lnkenter">Enter</a>
</div>
<a href="" class="bntesatico" id="lnkregistro">Sign up</a>
</header>
</body>
</html>
<script type="text/javascript">
$(document).ready(function(){
$('#lnklogin').click(function() {
$('#dvlogeo').fadeToggle(200, function() {
var divID = $('#dvlistipopubs');
var openDiv = $(this).is(':visible') ? divID : null;
});
return false;
});
$('#lnkenter').click(function() {
var usremail=$('#txtusremail').val(),
password=$('#txtpassword').val();
$.ajax({
type: 'POST',
url: "account/login.php",
data: 'usremail=' + usremail +
'&password=' + password,
success: function(data) {
if(data=='ok'){
document.location="account/main.php"
}else{
alert('Access denied');
}
}
});
return false;
});
});
</script>
I used firebug to verify the answer from the server and is printing 'ok' if user and password are right and error if something is wrong, the problem is that is not working here
success: function(data) {
if(data=='ok'){
document.location="account/main.php"
}else{
alert('Access denied');
}
}
jquery ajax login
I have a problem with a simple login with ajax, apparently all is right, but I don´t know what is wrong, because I need to send a message to the client indicating that the user info is right and then redirect to main page.
Source Code
<!DOCTYPE html>
<html lang="es" >
<head>
<meta http-equiv='Content-type' content='text/html; charset=<? echo APP_CHARSET ?>' />
<title>Red Social Basica</title>
<? Tag::css('reset') ?>
<? Tag::css('design') ?>
<? echo Html::includeCss() ?>
<? echo Tag::js('jquery/jquery.min') ?>
</head>
<body class="fondobody">
<header class="topbar">
<a href="" class="bntesatico" id="lnklogin">Login</a>
<div id="dvlogeo">
User/Email<input type="text" id="txtusremail"/>
Password<input type="password" id="txtpassword"/>
<a href="" id="lnkenter">Enter</a>
</div>
<a href="" class="bntesatico" id="lnkregistro">Sign up</a>
</header>
</body>
</html>
<script type="text/javascript">
$(document).ready(function(){
$('#lnklogin').click(function() {
$('#dvlogeo').fadeToggle(200, function() {
var divID = $('#dvlistipopubs');
var openDiv = $(this).is(':visible') ? divID : null;
});
return false;
});
$('#lnkenter').click(function() {
var usremail=$('#txtusremail').val(),
password=$('#txtpassword').val();
$.ajax({
type: 'POST',
url: "account/login.php",
data: 'usremail=' + usremail +
'&password=' + password,
success: function(data) {
if(data=='ok'){
document.location="account/main.php"
}else{
alert('Access denied');
}
}
});
return false;
});
});
</script>
I used firebug to verify the answer from the server and is printing 'ok' if user and password are right and error if something is wrong, the problem is that is not working here
success: function(data) {
if(data=='ok'){
document.location="account/main.php"
}else{
alert('Access denied');
}
}
jquery ajax login
jquery ajax login
edited Nov 28 '13 at 15:22
Cyrus
1047
1047
asked Nov 28 '13 at 15:02
Alexander CeballosAlexander Ceballos
64811328
64811328
can you show your php file?
– Drixson Oseña
Nov 28 '13 at 15:11
2
what doesconsole.log(data)returns?, before if(data==....
– Cyrus
Nov 28 '13 at 15:12
Doessuccesseven trigger? If the response is not a200 OK, onlycompletewill trigger, notsuccess. Firebug has a Network tab. Check that for the response.
– Rudie
Nov 28 '13 at 15:31
Here is my php file, is a method because I am using MVC -> kupaste.com/ver/64167
– Alexander Ceballos
Nov 28 '13 at 15:32
The response is 200 OK
– Alexander Ceballos
Nov 28 '13 at 15:34
|
show 2 more comments
can you show your php file?
– Drixson Oseña
Nov 28 '13 at 15:11
2
what doesconsole.log(data)returns?, before if(data==....
– Cyrus
Nov 28 '13 at 15:12
Doessuccesseven trigger? If the response is not a200 OK, onlycompletewill trigger, notsuccess. Firebug has a Network tab. Check that for the response.
– Rudie
Nov 28 '13 at 15:31
Here is my php file, is a method because I am using MVC -> kupaste.com/ver/64167
– Alexander Ceballos
Nov 28 '13 at 15:32
The response is 200 OK
– Alexander Ceballos
Nov 28 '13 at 15:34
can you show your php file?
– Drixson Oseña
Nov 28 '13 at 15:11
can you show your php file?
– Drixson Oseña
Nov 28 '13 at 15:11
2
2
what does
console.log(data) returns?, before if(data==....– Cyrus
Nov 28 '13 at 15:12
what does
console.log(data) returns?, before if(data==....– Cyrus
Nov 28 '13 at 15:12
Does
success even trigger? If the response is not a 200 OK, only complete will trigger, not success. Firebug has a Network tab. Check that for the response.– Rudie
Nov 28 '13 at 15:31
Does
success even trigger? If the response is not a 200 OK, only complete will trigger, not success. Firebug has a Network tab. Check that for the response.– Rudie
Nov 28 '13 at 15:31
Here is my php file, is a method because I am using MVC -> kupaste.com/ver/64167
– Alexander Ceballos
Nov 28 '13 at 15:32
Here is my php file, is a method because I am using MVC -> kupaste.com/ver/64167
– Alexander Ceballos
Nov 28 '13 at 15:32
The response is 200 OK
– Alexander Ceballos
Nov 28 '13 at 15:34
The response is 200 OK
– Alexander Ceballos
Nov 28 '13 at 15:34
|
show 2 more comments
2 Answers
2
active
oldest
votes
Try using this code with function (responseText) ;)
success: function (responseText) { // Get the result and assign to each case.
if (responseText == 'ok') {
document.location = "account/main.php";
} else {
alert('Access denied');
}
}
});
add a comment |
Here's the solution I found, using JSON.
In my Ajax:
$.ajax({type: 'GET',
dataType: 'json',
url: "login.php",
data: 'usremail=' + usremail +
'&clave=' + clave
}).done(function(data) {
if (data.mensaje == "ok") {
document.location = "index.php";
} else {
$('#dvmsjlogin').html(data.mensaje);
}
});
And in my PHP:
if ($auth->authenticate()) {
$res['mensaje'] = 'ok';
}else{
$res['mensaje']='error';
}
echo json_encode($res);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f20269281%2flogin-with-ajax-jquery%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try using this code with function (responseText) ;)
success: function (responseText) { // Get the result and assign to each case.
if (responseText == 'ok') {
document.location = "account/main.php";
} else {
alert('Access denied');
}
}
});
add a comment |
Try using this code with function (responseText) ;)
success: function (responseText) { // Get the result and assign to each case.
if (responseText == 'ok') {
document.location = "account/main.php";
} else {
alert('Access denied');
}
}
});
add a comment |
Try using this code with function (responseText) ;)
success: function (responseText) { // Get the result and assign to each case.
if (responseText == 'ok') {
document.location = "account/main.php";
} else {
alert('Access denied');
}
}
});
Try using this code with function (responseText) ;)
success: function (responseText) { // Get the result and assign to each case.
if (responseText == 'ok') {
document.location = "account/main.php";
} else {
alert('Access denied');
}
}
});
edited Nov 24 '18 at 2:14
Davіd
3,67041735
3,67041735
answered May 12 '14 at 5:03
user3627103user3627103
1
1
add a comment |
add a comment |
Here's the solution I found, using JSON.
In my Ajax:
$.ajax({type: 'GET',
dataType: 'json',
url: "login.php",
data: 'usremail=' + usremail +
'&clave=' + clave
}).done(function(data) {
if (data.mensaje == "ok") {
document.location = "index.php";
} else {
$('#dvmsjlogin').html(data.mensaje);
}
});
And in my PHP:
if ($auth->authenticate()) {
$res['mensaje'] = 'ok';
}else{
$res['mensaje']='error';
}
echo json_encode($res);
add a comment |
Here's the solution I found, using JSON.
In my Ajax:
$.ajax({type: 'GET',
dataType: 'json',
url: "login.php",
data: 'usremail=' + usremail +
'&clave=' + clave
}).done(function(data) {
if (data.mensaje == "ok") {
document.location = "index.php";
} else {
$('#dvmsjlogin').html(data.mensaje);
}
});
And in my PHP:
if ($auth->authenticate()) {
$res['mensaje'] = 'ok';
}else{
$res['mensaje']='error';
}
echo json_encode($res);
add a comment |
Here's the solution I found, using JSON.
In my Ajax:
$.ajax({type: 'GET',
dataType: 'json',
url: "login.php",
data: 'usremail=' + usremail +
'&clave=' + clave
}).done(function(data) {
if (data.mensaje == "ok") {
document.location = "index.php";
} else {
$('#dvmsjlogin').html(data.mensaje);
}
});
And in my PHP:
if ($auth->authenticate()) {
$res['mensaje'] = 'ok';
}else{
$res['mensaje']='error';
}
echo json_encode($res);
Here's the solution I found, using JSON.
In my Ajax:
$.ajax({type: 'GET',
dataType: 'json',
url: "login.php",
data: 'usremail=' + usremail +
'&clave=' + clave
}).done(function(data) {
if (data.mensaje == "ok") {
document.location = "index.php";
} else {
$('#dvmsjlogin').html(data.mensaje);
}
});
And in my PHP:
if ($auth->authenticate()) {
$res['mensaje'] = 'ok';
}else{
$res['mensaje']='error';
}
echo json_encode($res);
edited Nov 24 '18 at 2:15
Davіd
3,67041735
3,67041735
answered Dec 11 '13 at 23:07
Alexander CeballosAlexander Ceballos
64811328
64811328
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f20269281%2flogin-with-ajax-jquery%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
can you show your php file?
– Drixson Oseña
Nov 28 '13 at 15:11
2
what does
console.log(data)returns?, before if(data==....– Cyrus
Nov 28 '13 at 15:12
Does
successeven trigger? If the response is not a200 OK, onlycompletewill trigger, notsuccess. Firebug has a Network tab. Check that for the response.– Rudie
Nov 28 '13 at 15:31
Here is my php file, is a method because I am using MVC -> kupaste.com/ver/64167
– Alexander Ceballos
Nov 28 '13 at 15:32
The response is 200 OK
– Alexander Ceballos
Nov 28 '13 at 15:34