Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript PHP jQuery
Hi All,
 
I am new to jquery ajax and php. I am creating a login page with emailid and password fields.
 
I have written a service to check the emailid and password with database table data. So I checked my webservice with Google Chromes 'Advanced Rest Client' plugins and it is showing me result as 'Login successfully' which was my intent, if user credentials are current with database then show this msg.
 
Now the main problem arises when i try to do this in browser eg. "localhost/myapp/Login.php" with two text boxes. When i hit submit button I get a blank message.
 
My js file code is as shown below,
 
$(document).ready(function() {

var emailid='';
var password='';
 
$('#btnsubmit').click(function(e)
{
emailid=$(#emailid).val();
password=$(#password).val();
 
if(emailid && password)
{
var userData='emailid='+ emailid +'&password='+ password;
 
Authenticate_User(userData);//call function
}
else
{
alert('I am in else condition of js file"');
}
 
});
 
function Authenticate_User(userData)
{
$.ajax({
url: 'services/Login.php',
type: 'POST',
data: userData,
contentType:'application/x-www-form-urlencoded',
//dataType: 'json',
processData: false,
success: function(data)
{
console.log('Success is here '+ JSON.stringify(data));
//window.Location('http://localhost/myapp/home.html');
//window.location='http://localhost/myapp/home.html';
alert('Success is here');
},
error: function(XMLHttpRequest,textStatus,errorThrown)
{
console.log('ERROR:' + JSON.stringify(XMLHttpRequest.responseText));
alert(JSON.stringify(XMLHttpRequest.responseText));

}
 
});
}
 
});
 
When I entry email id and password and clicks submit then it gives blank msg and then it i try to click submit button without any data i.e. if emailid and password are blank then it shows 'I am in else condition' which i have written up there....
 
Please suggest to get out of this problem ....
Posted 19-Mar-13 0:24am
Amol011693
Comments
Karthik Reddy at 19-Mar-13 8:49am
   
Try changing "url: 'services/Login.php'" to "url: '/services/Login.php'" in ajax request

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

emailid=$(#emailid).val();
password=$(#password).val();
 

 
shoulld be
 

emailid=$('#emailid').val();
password=$('#password').val();
  Permalink  
Comments
amolpatil011 at 19-Mar-13 5:37am
   
emailid=$('#emailid').val();
password=$('#password').val();
 
After making changes as per ur comment i still have the same problem

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 365
1 Sergey Alexandrovich Kryukov 329
2 BillWoodruff 210
3 Afzaal Ahmad Zeeshan 204
4 CPallini 185
0 OriginalGriff 5,515
1 DamithSL 4,451
2 Maciej Los 3,902
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 19 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100