Easy AJAX implementation into your websites

Now days, AJAX playing great role in web development. All of the web sites are done on the basis of AJAX because this technique makes internet applications smaller, faster and more user-friendly. Most of the students and initial web developers are trying to learn AJAX, while they started to learn, by seeing AJAX coding, they are off due to very huge coding and little bit non understanding etc., So, for them, it will be more useful to implement in easy way and they can understand what is happening inside AJAX code. Have a nice start in AJAX. Coding as follows,

Paste this java script in header section of your file and save it as “index.php”

<script type=”text/javascript”>
var http = false;

if(navigator.appName == “Microsoft Internet Explorer”) {
http = new ActiveXObject(“Microsoft.XMLHTTP”);
} else {
http = new XMLHttpRequest();
}

function ajaxfunction(ajaxval) {

http.open(“GET”, “ajax.php?passvalue=”+ajaxval, true);
http.onreadystatechange=function() {
if(http.readyState == 4) {
document.getElementById(‘output’).innerHTML = http.responseText;
}
}
http.send(null);

}

</script>

In body section, place below coding to give input and to get output.

<div id=”output”></div><!–this is place to print the result.–>
<form action=”" method=”get”>
<input name=”typesomething” type=”text” onkeyup=”ajaxfunction(this.value);” />
</form>

And then create a file called “ajax.php” in same directory (where u have placed index.php file). And then paste this coding on that file,

<?php
$passvalue=$_REQUEST['passvalue'];
echo $passvalue;
//Write your DataBase queries here and echo the output.
?>

Now run these codings, U got the answer.

You can leave a response, or trackback from your own site.

Leave a Reply