Ajax-Call : Password verification using ajax
Password verification using JavaScript-Ajax and HTML PHP.
To use this you have to include jQuery or use some jquery CDN and then create two file one for html code and other is for php and add the following code in and run on local host any one like xamp, wamp or some online server
<div>
<h1>The real password is admin</h1>
<input name="pass" type="password" id="pass" placeholder="Enter any password">
<input type="button" value="Check" onclick="check()">
</div>
<script type="text/javascript">
function check(){
var data = 'password='+document.getElementById('pass').value;
obj={
type:'post',
data:data,
url:'pass.php',
success:function(msg){ alert(msg); }
};
jQuery.ajax(obj);
}
</script>
To use this you have to include jQuery or use some jquery CDN and then create two file one for html code and other is for php and add the following code in and run on local host any one like xamp, wamp or some online server
Download Code
First for this we need an HTML file: say index.html
paste following code in it:
<div>
<h1>The real password is admin</h1>
<input name="pass" type="password" id="pass" placeholder="Enter any password">
<input type="button" value="Check" onclick="check()">
</div>
Then the Java-Script code for this including Ajax is:
<script type="text/javascript">
function check(){
var data = 'password='+document.getElementById('pass').value;
obj={
type:'post',
data:data,
url:'pass.php',
success:function(msg){ alert(msg); }
};
jQuery.ajax(obj);
}
</script>
And the PHP code is. the php file name is pass.php:
<?php
extract($_REQUEST);
if($password==="admin"){
echo "password matched";
}else{
echo "password not matched";
}
?>
Post a Comment