On keyup this text box sends a request to PHP and a value is returned.
html code
Send request to server without page refresh . Got it result on same page
test.html (file Name)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Ajax With Jquery</title>
<style type="text/css" media="screen">
#display{
padding-top:10px;
color: white;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(function() {
$('#cc').hide();
});
</script>
<script type="text/javascript" charset="utf-8">
function sendValue(str){
var action,sendToValue;
//alert(str);
$('#cc').show();
$.post("ajax.php",{action:"1",sendToValue:str},function(data) {
$("#display").html(data);
$('#cc').hide();
});
}
</script>
</head>
<body>
<p>On keyup this text box sends a request to PHP and a value is returned.</p>
<label for="txtValue">Enter a value : </label><input type="text" name="txtValue" value="" onblur="sendValue(this.value);" id="txtValue">
<div id="display"></div>
<div id="cc">Wait...</div>
</body>
</html>
ajax.php (file Name)
<?php
echo $action=$_POST['action'];
if($action==1){
$sendToValue=$_POST['sendToValue'];
echo "This is testing".$sendToValue;
}
?>
html code
Send request to server without page refresh . Got it result on same page
test.html (file Name)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Ajax With Jquery</title>
<style type="text/css" media="screen">
#display{
padding-top:10px;
color: white;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(function() {
$('#cc').hide();
});
</script>
<script type="text/javascript" charset="utf-8">
function sendValue(str){
var action,sendToValue;
//alert(str);
$('#cc').show();
$.post("ajax.php",{action:"1",sendToValue:str},function(data) {
$("#display").html(data);
$('#cc').hide();
});
}
</script>
</head>
<body>
<p>On keyup this text box sends a request to PHP and a value is returned.</p>
<label for="txtValue">Enter a value : </label><input type="text" name="txtValue" value="" onblur="sendValue(this.value);" id="txtValue">
<div id="display"></div>
<div id="cc">Wait...</div>
</body>
</html>
ajax.php (file Name)
<?php
echo $action=$_POST['action'];
if($action==1){
$sendToValue=$_POST['sendToValue'];
echo "This is testing".$sendToValue;
}
?>
No comments:
Post a Comment