<html>
<head>
<title>Ajax</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#submit').click(function () {
var name = $('.uname').val();
var pwd = $('.passwd').val();
var data='uname='+name+'&password='+pwd;
$.ajax({
type:"GET",
url:"logincheck.php",
data:data,
success:function(html) {
$("#message").html(html);
}
});
return false;
});
});
</script>
</head>
<body>
<form>
<label>Enter your Name</label>
<input type="text" name="uname" class="uname"/> <br/>
<label>Enter your Password</label>
<input type="password" name="password" class="passwd"/> <br/>
<input type="submit" id="submit"/>
</form>
<div id="message"></div>
</body>
</html>
The PHP file logincheck.php kept in the same folder as this one, runs as follows:
<?php $name = trim($_GET['uname']); $pswd = trim($_GET['password']); if (($name=="guest") && ($pswd=="jquery")) echo "Welcome ". $name; else echo "Sorry you are not authorized"; ?>
I cannot find anything wrong with the code, but when I enter name and password and click the button, nothing happens. No message is displayed, whether the username and password are correct or not. Any help?

New Topic/Question
Reply



MultiQuote




|