Click here to Skip to main content
15,912,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

As i am new to jquery and php, I was stuck at 1 point,

I have a login form with emailid and password in html. and i have written a webservice,if user logs in successfully then show home.html page else show login.html page.

Everything is working fine i.e. webservice in php is working fine. When i check using google chromes breakpoint and F10 then the result is showing correctly i.e. if user is abc@gmail.com and password is abc then it gives me the home.html page but this happens only when i use google chromes breakpoint,then only it shows me the correct result but it i try to run directly without any breakpoint then it shows me error with blank message.

Do you have any suggession on where i am going wrong.

JavaScript
$('#form').submit(function()    
    {
        var emailid = null;
        var password = null;
        var userData=null;

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

        userData='emailid='+ emailid +'password='+ password;
        alert(userData);
        if(emailid && password)
        {            
            Authenticate_User(userData);
        }
        else
        {
            alert('Email id and password cannot be blank');
        }
    });

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(XMLHttpRequest,textStatus,errorThrown)
					{
						alert('Success is here');
						console.log('Success is here' + JSON.stringify(XMLHttpRequest.responseText));						
						window.location.href = "home.html";
						
					},
			 error: function(XMLHttpRequest,textStatus,errorThrown)
					{
						console.log('ERROR: ' + JSON.stringify(XMLHttpRequest.responseText));
						alert(JSON.stringify(XMLHttpRequest.responseText));						
					} 		 
		}).done(function(data) { console.log(data); })
    .fail(function() { alert("error"); })
    .always(function() { alert("complete"); });
	}
Posted
Updated 19-Mar-13 7:14am
v2
Comments
Prasad Khandekar 19-Mar-13 15:08pm    
Hello Amol,

Try putting return false; ath end of the submit handler. More info on this can be found at http://api.jquery.com/submit/.

Regards,
Phionix11 20-Mar-13 7:09am    
hey thanx prasad....it works fine after ur post i added return false at the end and it worked. It was always giving me error if i try to run directly without breakpoint of google chrome. Now its working....Thanks again for your help and post :)

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900