I faced a problem when I want to use ajax to login, but no Answer!! the div error not show any message(success or Failed).
the html code is:
<script src="http://code.jquery.com/mobile/1.0a4/jquery.mobile-1.0a4.min.js"></script>
<script type="text/javascript" charset="utf-8" src="http://cdn.app-framework-software.intel.com/2.0/appframework.ui.min.js"></script>
<script>
function login() {
var par = "username=" + $('#username').val() + "&password=" + $('#password').val();
// window.alert(par); printed
$.ajax({
type: 'POST',
url: 'login.php',
data: {username: $('#username').val(), password: $('#password').val()},
success: function(response) {
$('#error').html(response);
}
});
}
</script>
</head>
<body>
Username: <input type="text" id="username"/><br>
Password <input type="password" id="password"/><br>
<button onclick="login()">Login</button><br>
<label id='error'>hh</label>
</body>
the login.php code above has no errors and get the result correctly but the problem in ajax code
$qry = "SELECT username, password FROM user WHERE username= '$uName' and password= '$pWord'";
$res=mysql_query($qry);
$checkUser=mysql_num_rows($res);
if($checkUser > 0){
echo "success";
}
else {
echo "Failed";
}
?>
I have checked your code and found that it is working.
Please check the the htmlcode file and login file is present on the root at same level.
If you still face the problem then save the html file as php and then try..
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments