pTutorial

New way to learn Programming

Ajax Example with PHP

Instant value

Following Ajax program example print the instant result that you type in the text box using Ajax.

Instant value example

<!--index.html-->
<html>
<head>
<script>
var request;
function table()
{
var u=document.frm.num.value;
var url="argument.php?val="+u;
if(window.XMLHttpRequest){
request=new XMLHttpRequest();
}
else if(window.ActiveXObject){
request=new ActiveXObject("Microsoft.XMLHTTP");
}
request.onreadystatechange=getInfo;
request.open("GET",url,true);
request.send();
}
function getInfo(){
if(request.readyState==4){
var val=request.responseText;
document.getElementById('uk').innerHTML=val;
}
}

</script>
</head>
<body>
    <h2>Please Enter your anything to check response</h2>
<form name="frm">
<input type="text" name="num" onKeyUp="table()">
</form>

<span id="uk"> </span>

</body>
</html>

PHP FILE

<?php
 //argument.php
$num=trim($_GET["val"]);
echo $num; 
 
?>

See Also


QUOTES OF THE DAY

Tomorrow life is too late, live today.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER