Ajax is a technology that helps us load the data from server without loading the whole page.
We can make ajax calls that send requests to server and display the result on the fly without loading the page.
Below java script code will demonstrate how we can use ajax in php.
xmlhttp.open("GET","ajaxserverpage.php?p="+param,true);
xmlhttp.send();
We can make ajax calls that send requests to server and display the result on the fly without loading the page.
Below java script code will demonstrate how we can use ajax in php.
<script>
function getajaxdata(param)
{
xmlhttp=new XMLHttpRequest();
function getajaxdata(param)
{
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
alert ( xmlhttp.responseText );
}
}
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
alert ( xmlhttp.responseText );
}
}
xmlhttp.open("GET","ajaxserverpage.php?p="+param,true);
xmlhttp.send();
}
</script>
</script>
As shown above We have made an ajax call using below line
xmlhttp.open("GET","ajaxserverpage.php?p="+param,true);
Here what we are trying to do is calling the script in ajaxserverpage.php page .
When the server sends the response we are showing it to user. Normally you will display the response in some section on your page.
No comments:
Post a Comment